Rel = file-list href = "./ 23 design mode list .files / filelist.xml"> rel = edit-time-data href = "./ 23 design mode list .files / editdata.mso">
23 design patterns
23 design patterns
Create mode ... 2
Abstract Factory .. 2
Provide an interface to create a series of related or interdependent objects without specifying their specific classes.
2. Builder 2
Separation of a complex object is separated from its representation, making the same build process can create different representations.
3. Factory Method .. 3
Define an interface for creating an object, which allows the subclass to decide which class is instantiated. Make an instantiation of a class to its subclass.
4. Prototype .. 3
Use prototype instances to create the type of object and create a new object by copying these prototypes.
5. Singleton. 3
Ensure that a class has only one instance and provides a global access point access to it.
Structural mode ... 4
ADAPTER. 4
Convert a class interface into another interface that customers want.
2. Bridge .. 4
The abstract portion is separated from its achievement, so that they can be independently changed.
3. Composite .. 5
The object is combined into a tree structure to represent a "portion-overall" hierarchy.
4. Decorator. 5
Dynamically add some additional responsibilities to an object.
5. Façade .. 6
Provide a consistent interface for a set of interfaces in the subsystem, the FACADE mode defines a high-level interface, which makes this subsystem easier to use.
6. Flyweight. 6
Use sharing technology to effectively support a large number of fine-grained objects.
7. Proxy .. 7
Provide a proxy for other objects to control access to this object.
Behavior mode ... 7
CHAIN OF RESPONSIBILITY. 7
Many objects have the opportunity to handle the request, thereby avoiding the coupling relationship between the requested sender and the recipient.
2. COMMAND. 7
Pack of a request into an object so that you can use different requests to parameterize the customer; queuing or logging the request log, and supports the revocable operation.
3. Interpreter. 8
A language is given, defining a representation of its textual law, and defines an interpreter that uses this representation to interpret the sentence in the statement.
4. Iterator 8
Provides a method sequence accesses the individual elements in a polymeric object without exposing internal representation of the object.
5. Mediator 8
Use a intermediary object to encapsulate a series of object interactions.
6. MEMENTO .. 9
Under the premise of failure to damage the encapsulation, the internal state of an object is captured and the state is saved outside of the object.
7. OBServer 9
Define a one-to-many dependency between the objects, when the status of an object changes, all objects that depend on its object are notified and automatically updated.
8. State .. 9
Allow an object to change its behavior when its internal state changes.
STRATEGY. 10
Define a series of algorithms that package them one by one, and allow them to replace each other. 10. Template Method .. 10
Define the skeleton of an algorithm in an operation to delay some steps into the subclass.
11. Visitor. 10
Indicates the operation of each element acting in a target structure.
Create mode
A total of 5 kinds
1.
Abstract Factory
The abstract factory offers an interface to create a series of associated or interdependent objects without having to specify their specific classes. (Alias: kit) example description:
Interact
Favorable point
Advantages: (1) Package creation process. Customers don't know how the class is created, and the class is closed all created details. This can choose a different creative method, adding flexibility. (2) isolation of customers with specific classes and improve their reusability. Disadvantages: The Factory class level is usually parallel to the specific class level (ie, one or one correspond). Increase a specific class, generally adding a Factory class accordingly, increasing system complexity.
achieve
(1) The Abstract Factory class is usually a collection of Factory Method. Personally think that there is no essential difference with Factory Method mode. (2) The plant can usually use the plant as a single piece.
2.
Builder
The builder separates the build of a complex object with its representation, so that the same build process can create different representations.
The interaction between various types is shown below:
3.
Factory Method
The factory method defines an interface for creating an object, which allows the subclass to decide which class is instantiated. Make an instantiation of a class to its subclass. (Alias: Fictional constructor Virtual constructor)
4.
Prototype
Prototype Specify the type of object to create an object with prototype examples and create new objects by copying these prototypes.
5.
Singleton
One piece guarantees that a class has only one instance and provides a global access point access to it.
Structure mode
A total of 7 kinds
1.
Adapter
The adapter converts a class interface into another interface that customers want. The Adapter mode allows you to work with those classes that cannot be worked for by interfaces. (Alias: Wrapper Wrapper)
2.
Bridge
The bridge separates the abstraction section to its implementation part, so that they can change independently. (Alias: Handle / Body)
E.g
3.
Composite
The object is combined into a tree structure to indicate the "partial-overall" hierarchy. Composite enables users to have consistency for a single object and combined object.
4.
Decorator
Decoration Dynamically add some additional duties to an object. In terms of increased function, Decorator mode is more flexible compared to generated subclasses. (Alias: Wrapper Wrapper)
5.
Façade
The appearance provides a consistent interface for a set of interfaces in the subsystem, and the FACADE mode defines a high-level interface, which makes this subsystem easier to use.
6.
Flyweight
Enjoying the product uses sharing technology to effectively support a lot of fine-grained objects.
The most important concept in this mode is internal and external status. Internal status is stored in Flyweight, including external status independent of the Flyweight scene, which makes flyweight can be shared; external state depends on the Flyweight scene and is not shared according to the scene changes. The user is responsible for passing the external state to Flyweight when necessary.
1) Remote Proxy can hide the fact that an object exists in different address spaces; 2) Virtual Proxy can optimize, for example, when displaying a document containing large pictures, can not display pictures, only the size of the picture is displayed, as needed Create a picture object, display a picture; 3) Protection Proxies can access an object is additional in personal processing, such as permission verification, etc. 4) Smart Reference can intelligently manage the object referenced by the agent, such as the referenced object, no reference Release the object; set the object to the reference object, etc .; 7.
Proxy
The agent provides a proxy for other objects to control access to this object. (Alias: surrogate)
Behavior mode
A total of 11 kinds
1.
Chain of Responsibility
The duties chain make multiple objects have the opportunity to handle the request, thereby avoiding the coupling relationship between the requested sender and the recipient. Connect these objects into a chain and deliver the request along this chain until there is an object to process it.
The advantage of COR: Because which type is not presented from the outside, if each class encounters the request that it cannot be handled, as long as you give up. Undoubted this reduces the coupling between classes.
The disadvantage is that the efficiency is low because the completion of a request may be traversed to finally complete, and of course it can also be optimized with the concept of trees. In Java AWT1.0, the processing of the mouse button is to use COR. After java.1.1, use Observer instead of COR.
Due to the spread, because in COR, there must be a unified interface handler. Limitations are here.
2.
Command
The command packages a request into an object, allowing you to use different requests to parameterize the customer; queuing or logging the request log, and supports the revocable operation. (Alias: Action Action Transaction Transaction)
3.
Interpreter
The interpreter gives a language to define a representation of its textual law, and define an interpreter that uses this representation to interpret the sentence in the statement.
4.
Iterator
The iterator provides a method sequence to access the individual elements in a polymeric object without the need to expose the internal representation of the object. (Alias: Cursor Cursor)
5.
Mediator
The intermediaries encapsulate a series of object interactions with a mediation object. The intermediaries make the objects need not be explicitly cited to each other, making them rolling, and can independently change the interaction between them.
6.
MEMENTO
The memo captures an internal state of an object without damaging the encapsulation and saves this status outside of the object. This will restore the object to the originally saved state. (Alias: token)
Object interaction
Under normal circumstances, Memento is to access the private data of Originator, and a method is to set MEMENTO to ORIGINATOR, let Memento take the data itself. Another method is Originator to tell MEMENTO to MEMENTO.
7.
Observer
Observer defines a one-to-many dependency between the objects, when the status of an object changes, all objects that depend on its object are notified and automatically updated. (Alias: Relying on Dependents, Release - Subscribe to Publish-Subscribe)
8.
State
The status allows an object to change its behavior when its internal state changes. Objects seem to modify its class. (Alias: Status Object Objects for State)
9.Strategy
Policies define a range of algorithms to encaps them one by one, and allow them to replace each other. This mode makes the algorithm can be varied independently of its customers. (Alias: Policy Policy)
10.
Template Method
The template method defines the skeleton of the algorithm in an operation, and delays some steps into the subclass. Template Method allows subclasses to redefine certain specific steps of the algorithm without changing the structure of an algorithm.
11.
Visitor
Visitors represent an operation of each element acting in a target structure. It allows you to define new operations for these elements without changing the class of each element.