Status mode and responsibility chain mode

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.