Create mode structure mode behavior mode
1.Factory Method Factory Method Creates an object and separated by using object responsibility. 1) Simple factory 2) Factory Method 3) Abstract Factory
2. Builder Creation Mode Separates a complex object's build with its representation, making the same build process can create different representations. Partial creation decoupling process and components
3. Prototype prototype Specify the type of object to create an object with a prototype instance and create a new object by copying these prototypes. The Prototype mode allows an object to create another customizable object, try not to know any details of how to create. The working principle is: By passing a prototype object to the object to be created, this object to be created is created by requesting the prototype object to create itself. Clone: Depth Cloning
4. Singleton single case ensures that only one instance is available. Use occasion: Control of resources. EG Database Connection Pool, System Parameter Configuration, Runtime, Calendar ... Implementation: 1) Sprife: Double-Checked Locking (DCL) - Multi-threaded resource deprive. Multiple class loaders load makes a single case possible possible. 2) Non-lazy model: recommendation.
5. ADAPTER adapter The two incompatible classes are used together, belong to the structural mode, and there is two identities that Adaptee and Adaptor (adapters). Composition and inheritance (inheritance). Java does not support multi-inheritance, available interface implementation.
6. Bridge bridge mode is divided into abstraction and behavior, each independent, but can dynamically combine.
7.Composite combination Tissues objects to achieve a "part-overall" hierarchy such that the client has consistency for a single object and combined object. Composite is easier to understand, thinking that Composite should think of the tree structure diagram. These objects have a common interface. When the method of the assembly is executed, Compositerator will traverse the entire tree structure, find the object that contains this method and implements the call execution. You can use it to take a hundred to describe it. First define an interface or abstraction class, which is a generic way of design mode. Other design patterns are not limited to the interior of the interface, but composite has a regulation, that is, to define an interior to access and manage the Composite assembly. Objects (or part component ").
8. Decorator Decoration Modes Dynamically add some additional duties to an object. EG, 1) IO: BUFFEREDReader Br = New BufferedReader (New FileReader); 2) Extend the AWT, SWING component. ...
9. Facade appearance provides a consistent interface for a set of interfaces in the subsystem. A typical application of Facade is the application of database JDBC.
10.FlyWeight Enjoyment Mode Internal Status: Intrinsic External Status: Extrinsic Shared Internal Status Element, Manage Flyweight Pool by Flyweight Factory. 11.Proxy proxy mode provides a proxy for other objects to control access to this object. Usage: 1) Authorization Mechanism The different levels of users have different access rights to the same object. 2) A client cannot operate directly to an object, but it must be interacted with that object. 3) Copy-On-Write Optimization Dynamic Agent, EG: Agent JDBC Connection, intercepting the Close method, returns the connection pool (simple powerful but resource).
12.observer observer mode
Similar to the listener, callbacks through the interface.
13. Memento Memo Machine The object of another object is copied, so that the object can be restored to the originally saved state. Historical records, resource (if you can combine the enjoyment of the energy mode).
14.State Status mode Usage before using status mode, the client needs to intervene in changing state, and the implementation of the state change is trivial or complex. After using the status mode, the outside of the client can use the event EVENT implementation directly. It does not have to care about how the event causes the state change, which is implemented inside the state machine. This is an Event-Condition-State, and the status mode encapsulates the Condition-State section. Each state forms a subclass, each state only cares about its next possible state, so that the rule of state transition is formed in invisible. If the new state is added, only the previous state modifications and definitions are involved. There are several ways to implement: one implement next () in each state, specifying the next state; there is a method, set a stateEnter, set the stateEnter state entry and STATEEXIT status to exit behavior.
15.Command Command Mode The command is packaged in a class, then the user (caller) is operated again. A good reason to use the Command mode is also because it enables the UNDO function, each specific command can remember the action it just execute and recovered when needed.
16.Chain Of Responsibility Duty Chain Cor. Cor. Trying to process a request request request with a series of classes, these classes are loose coupling, the only common point is to pass the request between them. 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. Demand is poor, because in COR, must have a unified interface handler, limitations are here. Difference to the Command mode: Command mode requires the call relationship between the client and the server side in advance, such as 1 represents Start 2 represents Move, etc., all of which are encapsulated in the Request, reach the server. Decompose. The COR mode does not require this prior agreement, and the server side can use the COR mode to perform a guess test for client requests. 17.Template template mode Defines the skeleton of an operation algorithm to delay some steps to its subclass. The abstract class of Java is Template mode.
18. Strategy Policy Defines a series of algorithms to encapsulate these algorithms into separate classes.
19. MEDiator agent uses a mediation object to encapsulate a series of object interactions. Why use Mediator? There are many interactions between individual objects; each object's behavior operation relies on each other to modify the behavior of an object, and it will involve modifying many other objects. If you use Mediator mode, you can make each object. The coupling between the objects is loose, just care about the relationship between the Mediator, so that many-to-many relationships become a pair of relationships, which can reduce the complexity of the system and improve the scalability.
How to use? // There is one interface to define the interaction between member objects:
Public interface mediator {}
// Meiator is implemented in specific implementation of interactive operation:
public class ConcreteMediator implements Mediator {// assumed that the current has two members private C1 c1 = new C1 ();. private C2 c2 = new C2 (); ...} public abstract class Colleague {private Mediator mediator; public Mediator getMediator ( ) {Return mediator;} public void setmediator (mediator mediator) {this.mediator = mediator;}}
Public class c1 extends colleague {...} public class c2 extends colleague {...}
// Each member must know Mediator and contact Mediator instead of contact with other members / (note that C1 and C2 Mediator must be the same.
20. Interpreter Interpreter Defines the textual method of the language and establishes an interpreter to explain the sentence in the language. Interpreter seems to use the surface is not very wide, it describes how a language interpreter is constituted.
21. Visitor Accessor mode acts on the operation of each object in a target group. It allows you to define new operations for these objects without changing these object itself.
22.iterator iterative mode provides a unified access method to the outside without exposing the internal data structure. Reference: http://www.uml.org.cn/sjms/sjms.asp http://www.jdon.com/designpatterns