State mode of learning notes in design 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.

The roles involved in state mode are:

Environment (context) role , as well as context: defines the interface to which the client is interested, and preserves an instance of a specific State class. An instance of this specific State class gives the existing state of this environment object.

Abstract State Role : Defines an interface that encapsulates the behavior of a particular state of an environment (context) object.

specific status (concretestate) role : Each specific state class implements the behavior of a state of the environment (context).

Applicable scenarios:

1. The behavior of an object depends on its state, and it must change its behavior according to the state at run time.

2. An operation contains a large, multi-branched structure, and these branches are determined by the state of the object.

State mode of learning notes in design 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.