Status mode and responsibility chain mode
When I learned the design model, I found that the state model is very similar to the responsibility chain model. At that time, I could not understand it. Now I will look back and check
I checked the information and understood a little. I first wrote down my understanding and continued to study in the future.
I. Status Mode
When the internal state of an object changes, it is allowed to change its behavior. This object seems to have changed its class.
Class Diagram
The Context class is a State defined by the user, and the abstract State class State is used to solve a specific State.
Multiple sub-classes will select different sub-class methods for different user-defined states. It can be said that the abstract class State is the solution to the Context class,
Its subclass is a different method divided into different States (the relationship between the State class and its subclass can be understood as a composite relationship)
Ii. Responsibility Chain Model
So that multiple objects have the opportunity to process the request, so as to avoid coupling between the request sender and the receiver. Link this object into a chain
And pass the request along this chain until an object processes it.
Class Diagram
Handler is an interface class under which objects are used to process user requests. They will be executed in a certain order until there is
Objects can be processed
Iii. Comparison
From the above, there is almost no difference between the two. What are the two models? In fact, the difference between the two is quite big.
1. Different perspectives for Problem description: The state mode is described from the user's state; the responsibility chain mode is described from the manager's perspective.
The results of object processing problems are both true or false.
2. The State mode reflects different states of the class. The responsibility chain mode reflects the same problem of different classes.
3. The subclass of the state mode is separated from the abstract class. The responsibility chain mode is a structure optimization for a class of problems, which is strict when dealing with problems.
Level relationship
Iv. Summary
These two models are only a little theoretical understanding, and need to be done in practice. They must be used in data center cooperation.
These two models deepen the relationship between the two