Behavior mode involves algorithm and inter-target assignments, involving communication between classes and objects.
Responsibilities Chain mode Chain of Responsibility
Name: Duty Chain Mode, Responsibility Chain Mode
problem:
Consider a online help system, we click to help keyword context according to the user, if there is no suitable right, if we display as close as possible, for example, the text dialog button is different from the window of the window. Naturally we need an object in an interface object to handle help requests, as for which object needs to be determined according to the site and available help. But the object of submitting the problem (such as buttons) does not know who the final help provider, we need a mechanism to let the object to help information with the object to help the letter.
solve:
Give multiple objects to process the opportunity to request, so that the sender and the recipient are solved. The request is passed along the processing chain to each object until one of them processes it.
effect:
Inter-necked objects are closely related. Make the objects that processes the requests can be determined at runtime (not the designs are required to be determined); and the request is transferred to multiple objects when it is not clearly specified, the objects on the chain may be uncertain. But attention, there is no guarantee that the request must be processed (so we need to specify the countermeasure guarantee request can be processed)
Photo:
Command mode Command
Name: Command Mode, Action Mode (Action), Trading Mode (Transaction)
problem:
When we issue a request to an object, do not know the details of the requested object on the details of the request, and the details of the recipient. For example, the toolbar includes a menu and a button, responding to user input, but the toolbar designer cannot know the request to obtain the recipient (who is who) or execution.
solve:
The request becomes an object such that the toolbar can send a request to any object (pass the request object), which can be stored and forwarded. That is, a Command class is defined, defining the interface of the execution operation, and the specific command class's words implement the specific operation, and the actors should implement, at which time the recipient has a command request, the command subclass can be performed smoothly. .
effect:
Take the object of the object to be operated with the object
Command object can be expanded
You can comply with multiple commands
You can also expand new commands without modifying existing classes.
Photo:
Interpreter mode
Name: Interpreter mode
problem:
If a particular type of problem occurs very high, we deserve to describe the various instances of the problem as a sentence, and process the sentence through a dedicated interpreter to solve the problem. For example, the pattern matching of search strings, we use credit expressions to resolve.
solve:
Inciting the common part of the problem, then process, design interpretation, write a statement for specific instances, using an interpreter to explain the statement.
effect:
Easy to change and expand syntax.
Easy to implement interpretator grammar, but for more complex grammar, interpreter implementation and maintenance difficult.
Added new expressions to help solve the problem for problems.
Photo:
Itecher mode
Name: Iterator Mode (Iterator), Cursor Mode (CURSOR)
problem:
For aggregated objects, they do not want to expose their internal structures to the outside, and hoped that they can be accessed in different ways. However, even if it is expected to go to all traversal operations, it is impossible to be stupid to the interface in the interface.
solve:
Separating access and traversal operations into an iTrator (iterator) defines an interface to access the list and track the current state. Different list objects deliberately realize their own iterators. effect:
A polymerization can be traversed in a variety of ways, but simplify the aggregated interface, multiple traverses can be implemented on the same aggregation (because the status maintenance is maintained by each Iterator).
Photo: