Status mode: observer and status Mode

Source: Internet
Author: User

When cooperating with the data center charging system, we found that the observer mode, status mode, and responsibility chain mode can be used in the on-and off-server scenarios. They are both behavior-oriented, but they are different.

 

Observer Mode

 

 

My blog link:Observer mode of data room Charging System.

 

Observer mode:A target object manages all observer objects that depend on it and actively sends notifications when its status changes. This is usually done by calling the methods provided by various observers.

 

Condition used: when an object needs to change other objects at the same time, and does not know how many objects need to be changed.

 

Different from the status mode: it has two aspects (SubjectAnd observer), and one aspect depends on another. In this case, the observer mode can encapsulate the two in an independent object so that they can change and reuse independently. The specific subject classes can be on, down, and forced down.Observer isDetermine whether the card exists, whether the card balance is sufficient, whether the card is on the machine, add the computer records, modify the computer records, and modify the card balance.

 

 

Status Mode

 

 

My blog link:Design Mode-status Mode.

 

State mode: allows an object to change its behavior when its internal state changes. This object seems to have changed its class.

 

Condition used: the behavior of an object depends on its state, and it must change its behavior according to its state at runtime. Or an operation contains a large multi-branch structure, and these branches depend on the object state. Or when the conditional expressions that control the state of an object are too complex.

 

Unlike the observer mode:Transferring the status judgment logic to a series of classes that indicate different states can simplify the complicated judgment logic.The specific State is to determine whether the card exists, whether the card balance is sufficient, whether the card is on the machine, and add the machine records.

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.