The original * * * * may need to change the application, separate them (encapsulated), and do not mix with the code that does not need to change.
The original * * * for interface programming, rather than for implementation programming, here for interface programming really mean "for super type Supertype programming", the key is polymorphism.
The original * * * Multiple use combination, less with inheritance.
Mode * * * * Strategy mode (Strategy pattern): Defines the algorithm family (a group of classes or methods), packaged separately, so that they can replace each other, this pattern allows the algorithm to change the independent client using the algorithm.
——————————————————————
The original * * * for the interaction between the loose coupling design efforts.
MODEL * * * Observer mode: Defines a one-to-many dependency between objects (the observer relies on the observable or the subject), so that when an object changes state, all its dependents are notified and automatically updated.
The JAVA.UTIL package has built-in observer patterns that make it easier to implement the pattern, but the observer pattern is flawed.
———————————————————————
Inheritance is statically determined at compile time, all subclasses inherit the same behavior, and the combination extends object behavior and relies on delegates, which can be extended dynamically at run time.
The original * * Open and Close principle: class should be extended development, to modify the closure.
It is impossible to make every part of the design follow the open and closed principle, focus on the most likely change in the design, and then use the open and closed principle.
The decorator can be seen as a wrapper.
Both the adorner and the decorated person have the same super type.
Because the decorator and the decorated person have the same super type, so in any need to be decorated in the occasion, can be decorated with the replacement.
The decorator can add his or her own behavior before/after the act of entrusting the decorated person, and even remove the decorated person's behavior for a specific purpose.
Mould * * Decorator Mode: Dynamically attaching responsibilities to objects, and to extend functionality, adorners provide more flexible alternatives than inheritance.
Adorners are often created in a pattern similar to a factory (factory) or builder (builder) to prevent decorative coding errors.
————————————————————————
A static factory method gets an object that does not need to create an object to instantiate the object, but its disadvantage is that the behavior of creating an object method cannot be changed by inheritance.
Modular * * * Factory Method Mode: Defines an interface for creating objects, but subclasses decide which class is instantiated. The factory method lets classes defer instantiation to subclasses.