"Design Patterns" Theory Integration + Application Scenarios (1)

Create mode:

8. Lei Feng is still in the world---factory method mode

       Defines an interface for creating objects, letting subclasses decide which class to instantiate. The factory method delays the instantiation of a class due to subclasses.

       The lonely and widowed elderly are cared for. She does not need to know who the specific caregiver is, as long as she knows that someone will take care of her.

9. Resume Copy---Prototype Mode

       Use the prototype instance to specify the kind of object to create, and bake the objects created by these prototypes.

13. Every good dish has a different aftertaste---builder mode

       Separating the construction of a complex object from its representation allows the same construction process to create different representations.

For example, to create a villain, whether fat or thin, you need to have hands, feet, and a head. Build the content in advance so that there will be no lack of arms and legs (whether the cooking is salted or not).

15. Can I not pay back the DB? ---Abstract factory pattern

       Provides an interface for creating a series of related or interdependent objects without specifying their concrete classes.

21. Some classes also need family planning---singleton mode

       Guarantees that there is only one instance of a class, and provides a global access point to it.

Structural Patterns:

6. What is so important to wear? --- Decorative Mode

         To dynamically add some additional responsibilities to an object, the decorator pattern is more flexible than subclassing in terms of adding functionality.

         Encapsulates the sequential behavior of dressing together

7. Making wedding dresses for others---agent mode

       Provides a proxy for other objects to control access to this object. That is, introduce a certain degree of indirection when accessing objects, and because of this indirection, multiple uses can be attached.

       Application scenarios:

       Remote Proxy - Provides a local representation for an object in a different address space. This hides the fact that an object exists in a different address space.

       Virtual proxies - create expensive objects on demand. It is used to store real objects that have been instantiated for a long time.

       Security proxies - used to control permissions when accessing real objects.

Smart Directing - means that when the real object is called, the proxy does something else.

12. Will bull market stocks still lose money? ---Appearance Mode

       Providing 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.

       Add intermediate interface - Foundation. It perfectly embodies the Dependency Inversion Principle and the Law of Demeter, one of the very commonly used patterns. Time of use: early design, development, maintenance.

17. In NBA I need translation---adapter mode

       Convert the interface of a class to another interface that the client wants. The adapter pattern enables classes to work together that would otherwise not work together due to incompatible interfaces.

       The things you need are in front of you, but you can't use them, and you can't transform them in a short time, so you need to find a way to adapt them. However, it is generally used in the post-maintenance phase.

19. Branch = one department---combination mode

       Group objects into tree structures to represent part-whole hierarchies. The composite mode allows users to use individual objects and composite objects consistently.

        Apply the management model of the head office in the branch

22. When will the mobile phone software be unified---bridge mode

       Separate the abstraction from its implementation so that they can both be changed independently. Separation of abstraction from its implementation doesn't mean to separate an abstract class from its derived classes, because it doesn't make any sense. Implementation refers to the objects an abstract class and its derived classes use to implement their own.

 

26. Don't be silly if you have too many projects---Flyweight mode

       Use sharing techniques to efficiently support a large number of fine-grained objects.

       The Flyweight pattern avoids the overhead of a large number of very similar classes. In programming, it is sometimes necessary to generate a large number of fine-grained class instances to represent data. If you can find that these instances are basically the same except for a few parameters, you can sometimes drastically reduce the number of classes that need to be instantiated. If you can move which parameters out of the class instance and pass them in when the method is called, you can drastically reduce the number of individual instances through sharing. Such as: website sharing (used by multiple small businesses)
(To be continued...)

Guess you like

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