Behavior mode-status Mode

Source: Internet
Author: User
Using System;
Using System. text;
Using System. Collections. Generic;

NamespaceStatus Mode
{
/*
* State mode intent: allows an object to change its behavior when its internal state changes. The object seems to have modified its class.
*
* State mode scenarios: 1. When an object's behavior depends on its state, and it must change its behavior according to its state at runtime
* 2. The State judgment logic is transferred to a series of classes indicating different states, which can simplify the complicated judgment Logic
*
*/

/// <Summary>
/// Abstract state, defining public State Processing Methods
/// </Summary>
Public Abstract Class State
{
Public Abstract Void Handler (context );
}
/// <Summary>
/// Context to maintain a specific subclass of State
/// </Summary>
Public Class Context
{
Private State state;

PublicState state
{
Get{ReturnState ;}
Set{State=Value ;}
}

PublicContext (State state)
{
This. State=State;
}

PublicVoidRequest ()
{
State. Handler (This);
}
}

/// <Summary>
/// Status
/// </Summary>
Public Class Concretestatea: State
{
/// <Summary>
/// Set and change the status in the status Processing Method
/// </Summary>
/// <Param name = "context"> </param>
Public Override Void Handler (context)
{
Context. State = New Concretestateb ();
}
}

PublicClassConcretestateb: State
{
PublicOverrideVoidHandler (context)
{
Context. State=NewConcretestatec ();
}
}

PublicClassConcretestatec: State
{
PublicOverrideVoidHandler (context)
{
Context. State=NewConcretestatea ();
}
}

PublicClassAppclient
{
PublicStaticVoidMain (String[] ARGs)
{

Context=NewContext (NewConcretestatea ());
Context. Request ();
Context. Request ();
Context. Request ();

}

}
}

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.