big talk design pattern

  1. Strategy mode : It defines the algorithm family and encapsulates them separately so that they can be replaced with each other. This mode allows changes in the algorithm to not affect the customers who use the algorithm. The strategy pattern is used to encapsulate algorithms, but in practice, we have found that we can use it to encapsulate almost any type of rule. Whenever we hear during the analysis that different business rules need to be applied at different times, we can consider using the strategy pattern. The possibility of dealing with this change. [ Combination: The Context of the strategy mode is very important. Combine the Strategy member objects in the Context. When initializing the Context, select the appropriate Strategy object and call the algorithmInterface() of the corresponding Strategy object. Reference code understanding ]
  2. Decorator pattern : Dynamically add some additional responsibilities to an object. In terms of adding functionality, the decorator pattern is more flexible than generating subclasses. The decoration pattern puts each function to be decorated in a separate class, and has this class wrap the object it is to decorate, so when special behavior needs to be performed, client code can selectively, according to need at runtime, The object is wrapped with the decorator function sequentially. [ Inheritance + combination : The Decorator class in the decoration mode is very important. On the one hand, it inherits from the abstract class Component, and on the other hand, it combines the Component objects in the Decorator abstract class, and assigns the corresponding Component objects to the combined Component objects in the Decorator through the set method . The operation() operation in Decorator inherits from Component, and the content of its method body is: if the Component object combined in the Decorator is not empty, execute the operation() method of the Component object. The operation() method in each specific Decorator class will first call the operation() method of the parent class, so that the operation() operation in the Decorator can be executed and achieve the effect of layer-by-layer packaging. Reference code understanding]
  3. Proxy mode : Provides a proxy for other objects to control access to this object. [ Inheritance + combination : The Proxy class of the proxy mode is very important. By implementing the same interface as the proxy class and combining the proxy real entity class RealSubject object, calling the request() method of the proxy class is actually calling the proxy real entity The request() method of the entity class RealSubject object . Reference code understanding]
  4. Factory Method Pattern : Define an interface for creating objects and let subclasses decide which class to instantiate. A factory method delays the instantiation of a class to its subclasses. Since the simple factory pattern is not only open to extension, but also open to modification (every time a class is added, a new branch must be added to the factory method that generates an instance), which violates the "open-closed principle". The factory method transfers the internal logic judgment of the simple factory to the client code.
  5. Prototype pattern : Use prototype instances to specify the kinds of objects to create, and create new objects by copying these prototypes.
  6. Template Method Pattern : Define the skeleton of an algorithm in one operation, and defer some steps to subclasses. Template methods allow subclasses to redefine certain steps of an algorithm without changing its structure. The Template Method pattern takes advantage of it by moving invariant behavior to the superclass and removing duplication of code in subclasses. [ Inheritance + code reuse ]
  7. Facade Pattern : Provides a consistent interface for a set of interfaces in a subsystem. This pattern defines a high-level interface that makes the subsystem easier to use. Combination
  8. Builder Pattern : Decouples the construction of a complex object from its representation, allowing the same construction process to create different representations. Inheritance + Combination
  9. Observer pattern : Also known as publish-subscribe pattern. It defines a one-to-many dependency, allowing multiple observer objects to listen to a subject object at the same time. This subject object notifies all observer objects when their state changes, enabling them to update themselves automatically. Inheritance + Combination
  10. Abstract Factory Pattern : Provides an interface to create a series of related or interdependent objects without specifying their concrete classes. Inheritance
  11. State Pattern : Allows to change behavior when an object's internal state changes, the object appears to change its class. This pattern mainly solves the situation when the conditional expression that controls the state transition of an object is too complex. The complex judgment logic can be simplified by transferring the judgment logic of the state to a series of classes representing different states. Of course, if the judgment logic is very simple, then there is no need to use the "state mode". Combined with each other 】
  12. Adapter Pattern : Converts an interface of a class into another interface that clients need. The adapter pattern enables classes to work together that would otherwise not work together due to incompatible interfaces. Inheritance + Combination
  13. Memento Pattern : Capture the internal state of an object and save this state outside the object without breaking encapsulation. This allows the object to be restored to its original saved state at a later date. Combination
  14. Composition Mode : Groups objects into a tree structure to represent a "part-whole" hierarchy. The composite mode allows users to use individual objects and composite objects consistently. When the requirement is to reflect the structure of the part and the whole hierarchy, it is hoped that the user can ignore the difference between the composite object and the single object, and when all the objects in the composite structure are used uniformly, the composite mode should be considered. The composite pattern allows clients to use composite structures and individual objects consistently. Inheritance + Combination
  15. Iterator pattern : Provides a way to sequentially access the elements of an aggregate object without exposing the object's internal representation. The iterator pattern should be considered when you need to access an aggregate object and traverse whatever those objects are, or when there are multiple ways to traverse the aggregate. Provide a unified interface such as start, next, whether to end, which item is currently, etc. for traversing unnecessary aggregate structures. Combined with each other 】
  16. 单例模式:保证一个类仅有一个实例,并提供一个访问它的全局访问点。
  17. 桥接模式:将抽象部分与它的实现部分分离,使它们都可以独立地变化。使得每种实现的变化不会影响其他实现,从而达到应对变化的目的。【组合
  18. 命令模式:将一个请求封装为一个对象,从而使你可用不同的请求对客户进行参数化;对请求排队或记录请求日志,以及支持可撤销的操作。命令模式把请求一个操作的对象与知道怎么执行一个操作的对象分割开。【组合
  19. 职责链模式:使多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的耦合关系。将这个对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理为止。【组合
  20. 中介者模式:用一个中介对象来封装一系列的对象交互。中介者使各对象不需要显式地相互引用,从而使其耦合松散,而且可以独立地改变它们之间的交互。中介者模式一般应用于一组对象以定义良好但是复杂的方式进行通信的场合,以及想定制一个分布在多个类中的行为,而又不想生成太多的子类的场合。【互相组合
  21. 享元模式:运用共享技术有效地支持大量细粒度的对象。如果一个应用程序使用了大量的对象,而大量的这些对象造成了很大的存储开销时,可以考虑使用享元模式。
  22. 解释器模式:给定一个语言,定义它的文法的一种表示,并定义一个解释器,这个解释器使用该表示来解释语言中的句子。如果一种特定类型的问题发生的频率足够高,那么可能就值得将该问题的各个实例表述为一个简单语言中的句子。这样就可以构建一个解释器,该解释器通过解释这些句子来解决该问题。正则表达式就是一种应用。
  23. 访问者模式:表示一个作用于某对象结构中的各元素的操作。它使你可以在不改变各元素的类的前提下定义作用于这些元素的新操作。访问者模式适用于数据结构相对稳定的系统。如果一个系统有比较稳定的数据结构,又有易于变化的算法的话,使用访问者模式比较合适。【互相组合
  24. 以上来源     https://blog.csdn.net/doleria/article/details/72617663 
  25. git代码参考地址   https://github.com/echoTheLiar/JavaCodeAcc/blob/master/README.md/#design-pattern

Guess you like

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