Java design mode----State mode

Source: Internet
Author: User

State mode:

Allows an object to change its behavior when the internal state changes, and the object looks as if it had modified its class.

Points:

1. State mode allows an object to have different behavior based on its internal state

2. Unlike the program state Machine (PSM), the state mode is represented by the class

3. The context delegates the behavior to the current state object

4. By encapsulating each state into a class, we localize any changes that need to be made later

5, the state mode and the policy mode have the same class diagram, but they have different meanings

6. Policy mode usually configures the context class with behavior or algorithm

7. State mode allows the context to change behavior as the state changes

8. The state or context class can be controlled by the status change

9. Using state mode often leads to a significant increase in the number of classes in the design

10. The status class can be shared by multiple context instances

Java design mode----State mode

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.