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 ();
}
}
}