Design Patterns (structural model, behavioral patterns)

First, the structural model

1. Adapter mode
    through a concrete class by adapting the adaptation to the target interface, such as those otherwise incompatible classes can work together.
   For example: binary search and can quickly discharge (fitter) encapsulated into a DataOperation (target interface), and then the operation Adapter (adapter) to operate. [Adapter (QuickSort sortobj, BinarySearch searchobj)]
2. bridge mode
    an abstraction now to achieve some separation achieved without modifying the source code to replace the class basis so that they can be varied alone to meet the principle of opening and closing.
3. The combination pattern
      objects organized into a tree structure, and can be used to describe the part of the overall relationship.
      Example: to form a anti-virus software.

Member leaves them step by step to complete the antivirus software
    
4. decorative patterns
     without affecting other objects, dynamic and transparent Add the responsibilities to each object.

     Example: Creating a simple form -> form to add scroll bars -> The form becomes transparent form.        
5. Exterior mode

     subsystem a set of interfaces and provides a consistent interface to define an interface, this interface makes it easier to use the subsystem.
To achieve a loose coupling between the subsystems and the user ~
6. Flyweight

     its name: share certain common elements. Effective support a large number of small objects through the sharing of technology reuse, the system uses only a small number of objects.
Example: backgammon. The total can not move a subject to a small bar, it is present in the system only a white / Black objects can be displayed in different places.
7. Proxy mode

     the client can not directly refer to an object, the proxy mediates therebetween.
Example: When writing binary tree outside can not directly access the root node, so even through an interface to access to a private function to achieve the desired functionality.
Another example: VPN

II type of model


1. duty chain

   to isolate the sender and receiver, so that a plurality of objects are likely to accept the request, these objects together into a chain, and the chain along the transfer request until object handles it so far.
       Example: Find the file system.
        Note: does not guarantee that every request will be processed for a long chain of responsibility may involve multiple requests to be processed, the system performance may be affected, but when debugging is not very convenient.
2. Command Mode

    requestor does not know who the recipient is to reduce the coupling. Like going to a restaurant for dinner, the end point of meal and did not know what to cook you do, so make a new command easily added to the system, a great deal of flexibility.
 
3. Interpreter pattern

     defines a grammar of the language, and to establish an interpreter to interpret the language of the sentence
     Example: Robot set up, Down, left, right

4. iterator pattern
       is not exposed to the internal data traverses him.
       With too much, STL in the Iterator
5. intermediary model
       using an intermediary to isolate you and the recipient. Like the example above, you are separated by waiters and chefs, reduce coupling.
6. memorandum mode
       Without destruction of the package, capture of an object and the internal state of the object is stored outside, and so when the object changes, so that the object can always return to the previous appearance. Premise memory should be enough.
         Example: game point after the resurrection, etc. resurrection hung for a moment to the state before hanging.
7. Observer pattern
       -many dependencies between objects defined, when an object is changed, the other objects are updated automatically.
         Example: Someone comments on your micro-blog, you are prompted each notification bar.
8. The state model
        allows an object to change his behavior when its internal state changes.
         Example: check bank deposits, many digital green, yellow is less than 1000, arrears are red.
9. policy mode
         an algorithm encapsulated class, in use, the client desired selection algorithm itself, as the STL package sort, find the like.

10. The template method pattern
         c ++ in the template, too much use.
11. visitor pattern
        for the same object, different roles have different operation, so that the operation of the object to be flexible, easy to add a visitor, but the addition of new concrete elements would be contrary to the principle of opening and closing, so this abstract factory pattern and the same pattern, with the principle of opening and closing of the inclination.
         Examples: site visitors and administrators, there are different rights and operations.
 

Guess you like

Origin www.cnblogs.com/yanglang/p/12034027.html
Recommended