2004-08-31
The build mode and structural mode emphasizes the relationship between static class entities, and behavioral models are solved by communication relationships between class entities. A control process is desired in an object-oriented manner. Most of the past experiences are solved the package problem of the entity, and there is no deliberate understanding for the communication mode between the class, so some behavior patterns are relatively unfamiliar. There is also a reason is that there are many approximation of behavioral models and process-oriented things, causing a certain understanding of understanding. From the note, you can see the insufficient understanding, you can do some details for behavioral modes.
1 Chain of Responsibility - Behavioral Object Mode This is a "request" mode. He provides a thinking to solve the problem when "request" is passed between a set of structures, so I think this is just a way of thinking, and a "request" is the same as the chain. His concrete transmission method, except for the design of the chain, the most important thing is related to the structure of the target group. Of course, if there is no structure of the object group, we can also forcefully build a chain, although complicated and slight soil, but must be more flexible, not only control processing, but also control the chain.
In general, Composite mode and this mode are often together, and the document event model in Microsoft IE should use such modes.
2 Command - Behavior Object Mode The request is packaged as an object, so you can do some uniform processing, such as queuing, log, revocation, etc. Applicability: 1 is an object-oriented alternative 2 for the callback mechanism. Specify, arrange, and execute requests 3 in different periods. 4. Support the system of high-level operations on the primitive operation. This is common in the system that supports "transactions". Is it still not very thorough?
3, Iterator - behavior object mode encapsulates the traversal algorithm of the aggregated class into iterator, so that the internal representation of the package object. Iterator is divided into external and internal, externally flexible, and the internal incoming parameters are simple (only one need to operate), and internal Iterator automatically traverses all elements. The Iterator can encapsulate the algorithm, or only the status, by the polymerization class package algorithm, the Iterator of the package algorithm may destroy the encapsulation of the polymerization.
4, Mediator Mediator hopes to perform management of the relationship between multiple objects through a centralized object. Most of the components that can be reused have no association, while the relationship between them is completed by additional objects. In graphical programming, you can use this mode and the Listener mechanism (OBServer mode), more convenient, further unlocking the coupling of the central control object with other objects.
5. Memento / Token Primer (ORIGINATOR) (required to save status) Apply for a memo and save the status into the manner, then hand it over to the manager (Caretaker), when needed At the time, the manager handed the appropriate memorandum to the primary, and the primer will restore its own state. MEMENTO mode, from ORIGINATOR, separating the process of saving customer request status. And the storage and interpretation of MEMENTO is completed by Originator, ensuring the boundaries of the package. If the order of the memo and its return (giving primer) are predictable, the memo can store incremental changes.
6. Observer / Dependents / Release-Subscribe (Observer) and Observer (Observer) are critical objects, Suject, and unfixed Observer relationships, decouple this relationship It is the main function of this mode, and the Listener mechanism can be seen as an implementation of this model, of course, MVC is also a good application scenario in this mode. The difference from Mediator is mainly reflected in that OBServer is a decoupling process for associated relationships, while Mediator pays more attention to the functions performed by each object. 7. State / Status (Objects for Status) Allows an object to change its behavior while changing its status, making objects seem to modify their own classes. 1. Localize the behavior related behavior. 2, state conversion explicitly
We can convert the menu and operation of the window according to the status of the current window, which can be implemented in the State mode.
8, Strategy Encapsulate Algorithm to make it independent of other objects. In fact, this method and one algorithm function in the process are basically the same, but because the package has become a class, there will be some interfaces that are uniform for easy replacement features.
9. Visitor (visitor) The main purpose of this mode is to separate operations and objects, pursuing object reuse and simplicity, and alternative operations. Relatively, the Strategy mode is more pursuit of packaging operation, and the reuse of the operation is pursued. Observer, Mediator pursues the relationship between the separation objects and the object itself.
All of the above is the behavioral mode of the subject level, the following is the behavioral mode 1, Template defines the skeleton of an algorithm and delays some of the steps into the subclass. This kind of use is more, not much.
2. Interpreter This mode describes how to define a text method for a simple language, how to represent a sentence in this language, and how to explain these sentences. This approach is more obvious in the regular expression, in the conventional program application, especially in the upper layer application. expression :: = literal | alternation | sequence | repetition | '(' expression ')' alternation :: = expression '|' expressionsequence :: = expression '&' expressionrepetition :: = expression '*' literal :: = 'a' | 'b' | ... {'a' | 'b' | ...} *
Related key participants: 1, AbstractExpression (abstract expression, unified interface) 2, TerminalExpression (end symbol expression) 3, NonterMinalExpression (non-end express expression)