1.Singleton (single case)
Function: Ensure that the class has only one instance; provide a global access point
Reflected in JDK:
(1) Runtime
(2) NumberFormat
2.Factory (static factory)
Function :
(1) Create objects instead of constructors
(2) Method names are clearer than constructors
Reflected in JDK:
(1) Integer.valueOf
(2) Class.forName
3.Factory Method )
Function: Subclasses decide which class to instantiate
Reflected in JDK: Collection.iterator method
4.Abstract Factory (Abstract Factory)
Function: Create a certain type of object
Reflected in JDK:
(1 ) java.sql package
(2) UIManager (swing appearance)
5.Builder (constructor)
Function:
(1) Put the construction logic into a separate class
(2) Separate the construction logic of the class And performance
Reflected in JDK: DocumentBuilder (org.w3c.dom)
6.Prototype (prototype)
Function:
(1) Copy object
(2) Shallow copy, deep copy
Reflected in JDK: Object. clone; Cloneable
7.Adapter(Adapter)
Function: Make incompatible interfaces compatible
Reflected in JDK:
(1)java.io.InputStreamReader(InputStream)
(2)java.io.OutputStreamWriter( OutputStream)
8.Bridge (Bridge)
Function: Separate the abstract part from its implementation part so that they can all change independently
Reflected in JDK: Handler and Formatter in java.util.logging
9 .Composite (combination)
Function: Treat combined objects and independent objects consistently
Reflected in JDK:
(1) org.w3c.dom
(2) javax.swing.JComponent#add(Component)
10 .Decorator (decorator)
Function: Add new functions to classes; prevent the explosive growth caused by class inheritance
Reflected in JDK:
(1) java.io package
(2) java.util.Collections#synchronizedList (List)
11. Façade (Appearance)
Function:
(1) Encapsulate a set of interactive classes and provide consistent external interfaces
(2) Encapsulate subsystems and simplify subsystem calls
Reflected in JDK: java .util.logging package
12.Flyweight (flyweight)
Function: shared objects, saving memory
Reflected in JDK:
(1) Integer.valueOf(int i); Character.valueOf(char c)
(2) String constant pool
14. Proxy (proxy)
Function:
(1) Transparently call the proxy object without knowing the complex implementation details
(2) Increase the function of the proxy class
Reflected in JDK: dynamic Agent; RMI
15.Iterator (Iterator)
Function: Separate the iteration of the collection from the collection itself
Reflected in JDK: Iterator, Enumeration interface
16.Observer (Observer)
Function: Notification Object status changes are reflected in JDK:
(1) java.util.Observer, Observable
(2) Listener in Swing
Function: Used to coordinate the operations of multiple classes
Reflected in JDK: Swing's ButtonGroup
Function: Define the structure of the algorithm, subclasses only implement different parts
Reflected in JDK: ThreadPoolExecutor.Worker
Function: Provide different algorithms
Reflected in JDK: Four rejection strategies in ThreadPoolExecutor
Function: The request will be processed by the object on the chain, but the client I don’t know which objects the request will be processed by
Reflected in JDK:
(1) java.util.logging.Logger will delegate the log to the parent logger
(2) ClassLoader’s delegation model
Function:
(1) Encapsulate operations to make the interface consistent
(2) Decouple the caller and receiver in space and time
Reflected in JDK: Runnable; Callable; ThreadPoolExecutor
Function: No need to check for null every time, treat null value as if it were an object with the same interface
Reflected in JDK: Collections.EMPTY_LIST
Function: Use a set of classes to represent a certain One rule
Reflected in JDK: java.util.regex.Pattern
Class diagram: four arithmetic operations

如何在PHP后端功能开发中合理应用设计模式?设计模式是一种经过实践证明的解决特定问题的方案模板,可以用于构建可复用的代码,在开发过程中提高可维护性和可扩展性。在PHP后端功能开发中,合理应用设计模式可以帮助我们更好地组织和管理代码,提高代码质量和开发效率。本文将介绍常用的设计模式,并给出相应的PHP代码示例。单例模式(Singleton)单例模式适用于需要保

如何通过编写代码来学习和运用PHP8的设计模式设计模式是软件开发中常用的解决问题的方法论,它可以提高代码的可扩展性、可维护性和重用性。而PHP8作为最新版的PHP语言,也引入了许多新特性和改进,提供更多的工具和功能来支持设计模式的实现。本文将介绍一些常见的设计模式,并通过编写代码来演示在PHP8中如何运用这些设计模式。让我们开始吧!一、单例模式(Sing

本篇文章给大家带来了关于golang设计模式的相关知识,其中主要介绍了职责链模式是什么及其作用价值,还有职责链Go代码的具体实现方法,下面一起来看一下,希望对需要的朋友有所帮助。

随着数据的增长和复杂性的不断提升,ETL(Extract、Transform、Load)已成为数据处理中的重要环节。而Go语言作为一门高效、轻量的编程语言,越来越受到人们的热捧。本文将介绍Go语言中常用的ETL设计模式,以帮助读者更好地进行数据处理。一、Extractor设计模式Extractor是指从源数据中提取数据的组件,常见的有文件读取、数据库读取、A

单例模式是一种常见的设计模式,它在系统中仅允许创建一个实例来控制对某些资源的访问。在 Go 语言中,实现单例模式有多种方式,本篇文章将带你深入掌握 Go 语言中的单例模式实现。

设计模式的六大原则:1、单一职责原则,其核心就是控制类的粒度大小、将对象解耦、提高其内聚性;2、开闭原则,可以通过“抽象约束、封装变化”来实现;3、里氏替换原则,主要阐述了有关继承的一些原则;4、依赖倒置原则,降低了客户与实现模块之间的耦合;5、接口隔离原则,是为了约束接口、降低类对接口的依赖性;6、迪米特法则,要求限制软件实体之间通信的宽度和深度。

随着JavaScript的不断发展和应用范围的扩大,越来越多的开发人员开始意识到设计模式和最佳实践的重要性。设计模式是一种被证明在某些情况下有用的软件设计解决方案。而最佳实践则是指在编程过程中,我们可以应用的一些最佳的规范和方法。在本文中,我们将探讨JavaScript中的设计模式和最佳实践,并提供一些具体的代码示例。让我们开始吧!一、JavaScript中

在C#开发中,设计模式和架构选择是至关重要的。良好的设计模式和合适的架构选择可以大大提高软件的可维护性、扩展性和性能。本文将讨论一些在C#开发中常用的设计模式和架构选择,并给出一些建议。设计模式是解决特定问题的通用解决方案,它们可以帮助开发人员避免重复造轮子,提高代码的可重用性和可读性。在C#开发中,有许多常用的设计模式,如单例模式、工厂模式、观察者模式等。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1
Powerful PHP integrated development environment
