23 Design Patterns in Java

, , Factory Method (factory method pattern),
Prototype (original model pattern), Singleton (singleton pattern), Facade (facade pattern),
, , Composite (composite pattern),
, Flyweight (Flyweight pattern), Proxy (proxy pattern) ),
Command (command mode), Interpreter (interpreter mode), Visitor (visitor mode),
Iterator (iteration sub-mode), Mediator (mediator mode), Memento (memorandum mode),
Observer (observer mode), State (state mode), Strategy (strategy mode),
Template Method (template method mode),  


Adapter (adapter mode)
class: The adapter inherits the class to implement the interface, in which the output result required by the conversion layer interface is converted
Object : The class is defined as an object in the adapter class , only implement the interface, and then convert the output results required by the layer interface.
Interface : When you need to create an interface object, you need to implement all the methods of the interface. If the adapter abstract class is empty to implement all the interface methods, then when creating the adapter, You only need to implement the required methods to create an object of this interface.
 Builder (build mode)
 When there are many member variables, there are many construction methods and many parameters, so you can use the build method to return the object of the current class, each set The method returns an object of this class.
 Bridge (Bridge Mode)
 When there are two different types of abstract classes and interfaces that need to be used in combination, the bridge pattern can be used. The abstract class performs an abstract implementation, the interface performs various inheritance, and then the interface is put into the abstract class as a member variable. At that time, you can instantiate the specific abstract class according to the requirements, and then pass the implementation class object of the sub-interface to the implementation object of the abstract class for combination and encapsulation, and finally output the required combination result.
 
 Chain Of Responsibility (Chain of Responsibility)
 When an implementation class cannot complete the task, it requests its superior to handle it until a superior can handle it. An abstract class adds superior objects (member variables) to provide abstract methods that need to be processed. , the subclass implements the abstract parent class. When using it, the superior object is passed to the superior of the current subclass, and the method to be processed has been completed.
 
 Decorator (decoration mode)
 When we want to add some functions on the basis of an existing class method, we can create a decorator class that also implements the interface of this class, and directly call the implementation of this class in the implemented method. method, and add this class object as a member variable, then create a decorator subclass that needs to add functionality, override the method implemented by the decorator class, and add the required functionality at the same time.
 
 Factory (factory mode)
 1. Simple factory mode: The factory class is dedicated to creating instance objects, and different objects are created according to different parameters

2. Factory method mode: Define an interface for creating objects, and let subclasses decide which to instantiate A class, factory method delays the instantiation of a class to its subclasses

​3. Abstract Factory Pattern: Provides an interface to create a series of related or interdependent objects without specifying their concrete classes.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325779180&siteId=291194637