Summary of the big talk design pattern (28 design pattern definitions + simple comprehension)

Source: Internet
Author: User

Big Talk design mode This book is very creative and very suitable for beginners like me. It took about two weeks to finish reading the book, the code was all knocked over, and though there was no basis, it was a glimpse into the power of object-oriented. After reading no longer do not want to use the process-oriented language, such as VB, I think I was a VB fanatic, but now I almost do not want to use. Now I just want to write something about it. Use several design patterns. It may be the first time you touch these things, some of them are understood, but it is difficult to apply to actual programming; Some of them don't understand, but they can say something like that. Listen to seven period seniors said they had seen two times, asked to carry out the code, do not know this time we eight requirements how so low, I only looked at it again, but look very carefully. I know deeply that the design pattern is simply not understandable by looking at a book, let alone an entry-level book? I listen to miss Rice's teachings: Do not waste time on unnecessary details, and synthesize your own view: Some things can be better to figure out. The result is so that the book is finished, feel not to remember how many things, now take a summary of what I can not sum up, now everything is very vague, but if not summed up, the book is white, so I put each of the definition and simple understanding of the model list. These are just my understanding as a beginner, inevitably very simple, and very likely to have errors, forgive me! 1. Simple Factory mode: definition: A single class is used to complete the process of creating an object, that is, the factory class. Understanding: The production object of the factory, by the parameters generated by the corresponding object, easy to expand, and do not need to extend the existing functions. 2. Strategy mode: Definition: It defines the algorithm family, respectively encapsulated, so that they can directly replace each other, this pattern makes the algorithm better than Ah, does not affect the use of the algorithm of the customer. Understanding: It can be understood as a "protected simple factory model", encapsulating the Simple factory pattern, and fully shielding the factory from the client by coordinating the class call factory. 3. Single principle of Responsibility: definition: In the case of a class, there should be only one cause for it to change. Understanding: The duties of the class single, reducing the burden of the class. 4. Open-Close principle: definition: Software entities (classes, modules, functions, and so on) should be extensible, but cannot be changed. Understanding: Closed to modifications, open to extensions. The solution is abstract, with abstraction being the isolated change. 5. Dependency reversal principle: Definition: High-level modules should not be dependent on the underlying module, and two should be dependent on abstraction. Abstractions should not depend on detail, and detail should be dependent on abstraction. Understanding: The principle of dependence reversal is the principle and guideline of "closed-open". 6. The Richter substitution principle: definition: subtypes must be able to replace their parent type. Understanding: With an abstract class or interface as the parent class, when used, the parent class type "object variable" as a parameter, so that any one inherits the abstract class or implements the interface class subclass (the instance), is equivalent to the subclass substitution the parent class, exploits the polymorphic, can be perfect to achieve "modify closed, expand open." 7. Decoration mode: definition: Dynamic to add some additional responsibilities to an object, the decoration mode is more flexible than the generation of sub-classes in terms of adding functionality. Understanding: The separation of people and clothing, that high-level modules should not rely on the underlying module, through the clothing abstract class (interface), very good separation, the use of interfaces, the expansion of the implementation of the interface, embodies the principle of dependence on the abstract. 8. Proxy mode: definition: Provides a proxy for other objects to control access to this object. Understanding: None, very simple. 9. Factory method Mode: Definition: Defines an interface for creating an object, letting subclasses decide which class to instantiate. The factory method defers the instantiation of a class to its subclasses. Understanding: The factory as an interface, let the factory each create object function to implement this interface, to create different objects, through the abstraction, decomposition of the factory, thus closed the modification, add the new factory members only need to add the implementation of the interface class. However, it is not a good idea to put the pressure (duty) on the client to determine which object to create, making the client complex. 10. Prototype mode: definition: Specify the kind of objects created with the prototype instance and create new objects by copying the prototypes. Understanding: Prototype mode is the implementation of the ICloneable interface, the implementation of this interface unique clone method cloning itself. You need to focus on understanding the Menberwiseclone method. After understanding: Shallow copy is the clone itself, fully follow the rules of the Menberwiseclone method (Clone new object, field copy, reference only copy reference), that is, the outer object clone, the inner object reference. While the deep copy is to increase the processing means, let the inner layer class implement the ICloneable interface, when the outer layer class creates the object (new), the inner layer class clones itself, realizes the separation of the inner layer class. 11. Template Method Mode: definition: Defines an algorithm skeleton in an operation, and delays some steps into subclasses. The template method allows subclasses to redefine some specific steps of the algorithm without altering the structure of an algorithm. Understanding: When duplicate code in a subclass is promiscuous, the duplicated code is moved to the parent class, and the non-repeating (special) delay is implemented in the subclass with a virtual or abstract method. Define a holistic skeleton method in the parent class, which combines the implementation of the parent class with the implementation of the subclass to complete the function. 12. Dimitri rule: Definition: If two classes do not have to communicate directly with each other, then these two classes should not have a direct interaction, if one of the classes needs to invoke a method of another class, you can forward the call through a third party. Understanding: Reduce the direct coupling of unrelated classes and facilitate modification. 13. Appearance mode: definition: Provides a consistent interface for a set of interfaces in a subsystem that defines a high-level interface that makes this subsystem easier to use. Understanding: The integration of a series of subsystems with certain connections into the appearance of amethod, the complex interaction is done by the skin class, and the client only needs to invoke the method of the skin class. The appearance class is like an image-good interface for simple invocation by the client. 14. Builder mode: definition: Separates the construction of a complex object from its representation so that the same build process can create different representations. Understanding: A series of stable, common, complex assembly processes in the command class, the definition of the abstract parent class, using polymorphic to create different subclasses (products), the user only need to invoke the command class and specify the product. Isolate complex assemblies into command classes. 15. Observer pattern: definition: Defines a one-to-many dependency that allows multiple observer objects to listen to a Subject object at the same time (the notifier). This subject object notifies all observer objects when the state changes, enabling them to automatically update themselves. Understanding: When an object changes, it is necessary to notify other indefinite numbers of objects. The class of the change corresponds to the notifier, and the class being notified corresponds to the Observer. Can be implemented in a collection, both sides rely on abstraction (the notifier has an abstract notifier, the Observer has an abstract observer, which can easily be extended). You can also use delegates to significantly reduce coupling (the observer must designate the notifier, which is who to notify). 16. Abstract Factory mode: definition: Provides an interface to create a series of related or interdependent objects without specifying their specific classes. Understanding: Simple Factory Mode----Factory Method mode (abstract factory to separate plant functions)----Abstract Factory mode (refine abstraction, continue to refine each separate small factory, then divide into different methods (interface methods), create another branch of the plant, and realize the versatility under the current plant. )。 Reflection: Reflection is the ability to dynamically create instances of different classes, changing the creation of instances from compile time to runtime. You can replace switch, if, and other branch statements in Factory mode. Reflection requires a string to be instantiated in the form of the class, so you can use the variable substitution, greatly increased flexibility. 17. State mode: Definition: When an object's internal state changes to allow changes to its behavior, the object looks like it has changed its class. Understand: When the program is running, you need to constantly judge a condition (state), and then according to the conditions to perform different actions, you can consider using the state mode. State mode can eliminate the large branch judgment, transfer logic of different States and the action of each state to subclass of abstract State class. Let each subclass decide on the next state (each subclass is judged, the fulfillment performs its own function, and the next class is not satisfied until it is processed or the chain ends.) Each subclass only needs to know which of the next class is, without knowing the entire chain structure. 18. Adapter Mode: Define: Convert the interface of one class into another interface that the customer wants. This mode makes it possible for those classes that would otherwise not be able to work together because of incompatible interfaces. Understanding: The interface of a class is transformed into another form through a translation class (adapter Class),Call another class indirectly by invoking the desired interface of this translation class. 19. Memo mode: Define: Captures the internal state of an object without destroying the encapsulation, and saves the state outside the object. The object can then be restored to its previously saved state. Understanding: Memo mode saves the data in the box class (which shows that the data is stored outside the object) and then accesses the box through the memo management class. When the main class is saved, create a new instance of the box class, save the data, and give the instance of the box to the management class to be managed, and invoke the Management class managed box when recovering. 20. Combination mode: Define: Combine objects into a tree structure to represent a "partial-whole" hierarchy. The combined mode makes the user consistent with the use of individual objects and composite objects. Understanding: The core idea is the branch and the Leaf class. Branches can be branched (traversed), while leaves are not. Leaves can be understood as "functional terminal", the specific function of the realization, and the branch is able to traverse its branches containing branches, leaves of the branch. Branches or leaves belong to which branch to join the branch of the collection, through recursion to achieve the effect. 21. Iterator Pattern: definition: Provides a way to sequentially access individual elements in an aggregated object without exposing the object's internal representation. Understanding: None, simpler. 22. Singleton mode: definition: Guarantees that a class has only one instance and provides a global access point to access it. Understanding: To ensure that a class has only one instance, this responsibility should be placed in this class, and should not be decided by other classes. The method is to change the construction method of the class to private, to ensure that the outside world cannot be instantiated by new, and then provide a public static method to create the instance. Put the responsibility of the protection instance in this method (although the construction method is private, the inside of the class is accessible.) After the creation is successful, it is returned with this public static method for the caller to use. The advantage of this is that the client only needs to use the class, as to whether it is instantiated, how it is instantiated by the class itself, relieves the pressure on the client, and reduces the coupling. )。 23. Bridging mode: definition: Separates the abstract part from its implementation, so that they can all change independently. Understanding: Separating the abstractions that are mixed together and allowing them to be implemented individually. It is then re-integrated by compositing/aggregation. This reduces the coupling between classes, makes the structure loose, avoids the huge inheritance system, and enhances the reusability. Embodied in the code is the complex inheritance of the "method-parameter", "part" of the object as the "whole" method of the parameters, through the parameters of aggregation (just talked about the aggregation, the individual think the composition should not depend on parameters, it should be a "you have me, I have you" strong coupling structure). 24. Command mode: Define: Encapsulate a request as an object, so that you can use different ask to parameterize the customer, queue the request or log the request, and support the revocable operation. Understanding: The requester and performer are decoupled by the waiter class. 25. Responsibility Chain Mode:Definition: Enables multiple objects to have the opportunity to process requests, thus avoiding the coupling between the sender and the recipient of the request. Link the object to a chain and pass the request along the chain until an object handles it. Understanding: The class that has a certain responsibility (processing power) is abstracted into an abstract parent class, and the parent class includes the method to set the ancestor and the abstract processing method. The client is designed to have a superior relationship, and then calls the lowest and the object handling transaction, and when the class cannot be processed, it automatically calls its upper-level processing until it can be processed. The advantage is that by setting up superiors to string together the responsibility object, each part knows who the superior is, no need to understand the structure of the whole chain, and the requestor only need to call the lowest level of the responsibility of the object, and ultimately by which object processing the requestor does not know and need not know. Everything is done automatically. 26. Mediator mode: Definition: A Mediation object is used to encapsulate a series of object interactions. The mediator makes the objects not need to explicitly reference each other, so that they are loosely coupled, and can independently change the interaction between them. Understanding: The Mediator undertakes all complex communication, in the object of concern to specify the mediation class, in the mediation class to include all the objects of concern. The client does not directly interact with the mediation class by invoking the mediation method of the mediator in the object-focused way. 27. Enjoy meta mode: definition: Use sharing technology to effectively support a large number of fine-grained objects. Understanding: Through Usingsystem. Collections refers to the Hashtable class to manage objects. Give each class an identity (key), determine if the object exists by key, exist directly by key, do not exist, and then add the Hasthtable class object by adding it, note that key must be specified. 28. Interpreter mode: definition: Given a language, define a representation of its grammar and define an interpreter that uses that representation to interpret sentences in the language. Understanding: The Interpreter mode is to use "mini language" to express the problem of the program to solve, in the mini-language written "mini-program" to express specific problems. 29. Visitor Pattern: definition: Represents an operation that acts on elements of an object structure. It allows you to define new actions that act on these elements without changing the class of each element. Understanding: The ability is limited, the pattern is not understood temporarily. The above is my understanding of the design pattern, through the learning design mode, I think a pattern has not read, better judgment standard is will not write client, if a pattern after reading can not write out the client calling code, the explanation is not understand at all. In the initial stage of learning design patterns, to try to deliberately use design patterns, I believe that with the study deepened, to achieve the "hands without swords, Heart also no sword" the highest state.

Summary of Design patterns (28 design pattern definitions + simple comprehension)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.