C # object-oriented mode design 22nd Lecture: State state mode (behavior mode)

Source: Internet
Author: User
Tags case statement

(According to the msdn webcast courses)

Objects in different States often perform different actions.

Usually, we can use the switch... Case statement to solve the problem. However, if the state changes frequently, this must cause tight coupling between the object and the object. Of course, we should not deliberately adopt the design pattern to use the design pattern, because

In a single case, the adoption of the model may complicate the design. In the initial stage of the project, we recommend that you do not deliberately apply the model, but find the change point as needed and gradually reconstruct the design mode.

When the design mode is not used:

When a new state such as printing is added to a document, due to the tight coupling, the original Enumeration type and document class objects must be destroyed at the same time.

When the State mode is used:

In this mode, we only need to add a printingdocument class that inherits from stateddocument. You can assign a value to the document object in the stateddocument attribute during the call. At the same time, we can also predict to define the status switch in the stateddocument class.

<End>

Related Article

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.