GOF design mode Special annoyance

Source: Internet
Author: User

This period of time, the learning State is more general, idle when basic playing games, and research how to play a good game, finally through the play life of the Master of the system pa lol, jokes. In order to and "learning" friendship between the boat does not turn over, decided to the previous study of the GOF design model to do a simple review, here I just "knowledge of the Porter" ha. Geoscience Teacher's "Big Talk design Mode" a book is very good, although the publication has a small 10 years, but the knowledge point is clear and understandable, especially the final virtual design pattern beauty contest, very incisive on the design mode of the analysis of the comparison, to facilitate the selection and landing of the design pattern in combat.

GOF Model Summary:

1. Factory method: Define an interface for creating objects, and let subclasses decide which class to instantiate, and the factory method defers the instantiation of a class to subclasses. It is the basis of all creation patterns, and the others are different evolution in different scenarios.

2. Abstract Factory: Provides an interface to create a series of or related dependent objects without specifying their specific classes. It seems that the structure is very complex, but its structure is similar and well understood.

3. Builder: Separates the component of a complex object from its representation so that the same component process can create different representations.

4. Prototype: Specify the kind of objects created with the prototype instance and create new objects by copying the prototypes. In practice, the class that implements the Iclone interface is the implementation of the prototype pattern.

5. Single example: One of the most commonly used design patterns, the service class typically considers a singleton pattern, guaranteeing that a class has only one instance, and provides a global access point to access it.

1. Adapter: The interface of a class to convert to another interface that the customer wants, so that the original incompatible interface can work together, very simple, common is to modify the parameter list.

2. Bridging: Separating the abstractions and implementations so that they can vary independently and decouple by using aggregations instead of integrations. For the two volatile objects, in order to make their changes with the least possible impact, through their abstraction to interact, you can study blogger Holly blog http://www.cnblogs.com/houleixx/archive/2008/02/23/1078877.html.

3. Composition: Combining objects into a tree structure to represent a "partial-whole" hierarchy, combining patterns makes the user consistent with the use of individual objects and composite objects, most commonly the DOM tree.

4. Decoration: Dynamically add some additional responsibilities to an object, and in the case of added functionality, the adornment mode is more flexible than generating subclasses.

5. Appearance: Provides a consistent interface for a set of interfaces in a subsystem, and the appearance pattern defines a high-level interface that makes this subsystem easier to use.

6. Share: To use shared technology to effectively support a large number of fine-grained objects.

7. Proxy: Provides a proxy for other objects to control access to this object. Here to add, the agent, the appearance and the adapter pattern difference, the proxy object represents a single object and the Appearance object represents a subsystem, the agent's client object cannot directly access the target object, the agent provides the access control to the target object, and the appearance is usually the simplification of the subsystem components. The adapter does not need to be a fictitious representation, just provide a specific method.

1. Observer (Observer): Defines a one-to-many dependency between objects, and when the state of an object changes, all objects that have historically been notified and automatically updated. NET programs are both the most common examples. In addition, the common MVC architecture pattern is actually a combination of observers, combinations, and policy patterns.

2. Template method: Define an algorithm skeleton for an operation, and defer some steps into subclasses, and the template method allows subclasses to redefine some specific steps of the algorithm without altering the structure of an algorithm. This is also often used in development, where there are some aspect-oriented scenarios where a simple template approach can be used to achieve the same purpose, such as sharing exception handling and logging code, without using a third-party dynamic agent library.

3. Command: Encapsulate a request as an object so that you can parameterize the customer with different requests, queue up requests or log requests, and support revocable operations.

4. Status: Allows an object to change its behavior when its internal state changes, making the object appear to modify its class, which can make the common if-else branching structure more readable and maintainable.

5. Chain of responsibility: so that multiple objects have the opportunity to process the request, thereby avoiding the coupling between the sender and receiver of the request, linking the objects into a chain, and passing the request along this chain until there is an object processing, similar to the actual approval process, layers of submissions, know that there is permission to deal with the person so far, A common MVC filter is a concrete implementation of this pattern.

6. Interpreter: Given a language, define a representation of its grammar and define an interpreter. The usage scenario is that if a particular type of problem occurs at a sufficiently high frequency, it might be worthwhile to describe each instance of the problem as a sentence in a simple language so that an interpreter can be constructed that solves the problem by interpreting the sentences. For example, when a language needs to be interpreted and executed, and you can represent a sentence in that language as an abstract syntax tree, you can use the interpreter pattern.

Pros: It's easy to change and extend the grammar through inheritance, and it's easier to implement grammars, because the implementation of the classes that define the nodes in the abstract syntax tree is broadly similar.

A disadvantage; Because you need to define at least one class for each rule, it is difficult to maintain and manage when rules are complex, and it is recommended to use a parser or compiler builder to handle them.

7. Intermediary: Using an intermediary object to encapsulate a series of object interaction, the intermediary to the object is not allowed to explicitly reference each other, so as to achieve the purpose of decoupling, in line with the minimum knowledge principle.

8. Visitor Mode: Represents an operation that acts on elements of an object structure, allowing you to define new actions that act on these elements without altering the elements, which is a double-allocated structure that is more complex and requires more practice.

Advantage: It decouples the data structure from the action on it, allowing the set of operations to evolve relatively freely. When Objectstructure is stable, adding new operations becomes straightforward, adding a new visitor.

Cons: Complicates the addition of new data structures while increasing the complexity of the system.

9. Strategy: Define a series of algorithms, encapsulate them, and allow them to replace each other, independent of the customers who use it.

10. Memo: Without compromising encapsulation, capture the internal state of an object and save the state outside that object so that it can be restored to its previously saved state.

11. Iterators: Provides a way to sequentially access individual elements in an aggregated object without exposing their internal representations. NET iterator is an example of its implementation.

TIP:

An analysis of supplementary events and delegates, a delegate is the encapsulation of a function, which can be used as a name given to a method's characteristics, whereas an event is a special form of a delegate that handles the notification process when something meaningful happens. In addition, a delegate is a type that refers to a method, and once the delegate has been assigned a method, the delegate will behave exactly like a sea method, and the event is something that the class or object can notify them through events when other classes or objects of interest occur.

Resources

  1. geoscience big talk design mode [m]. Beijing : Tsinghua University Press
  2. [ US], Erich, Gamma, [ US ], Richard, Helm, [ US ], Ralph, Johnson. /c7> Design pattern: The basis of reusable object-oriented software [M]. Beijing : Mechanical Industry Press ,.

GOF design mode Special annoyance

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.