Class StatePattern.Context


public class Context
extends Object
This is the only public class in the package. and represents the class exhibiting multiple state behavior. The state design is fully encapsulated and hidden from the public view. This class is the environment in which the concrete states operate. All method calls dependent on the state of Context will be dispatched to the concrete state.


Variable Index

 o aState

Method Index

 o aMethod (Object)
This represents any generic method of the Context class, with input parameter(s) and an return value
 o setState (AState)
This method sets the state of the Context and effects a state transition

Variables

 o aState
private AState aState = new ConcreteStateA()

Methods

 o aMethod
public Object aMethod(Object aParam)
This represents any generic method of the Context class, with input parameter(s) and an return value. It is shown here to illustrate the addition of the Context parameter during the dispatching to the abstact state.

Parameters:
aParam - Any input parameter(s)
Returns:
Any return value
 o setState
void setState(AState aState)
This method sets the state of the Context and effects a state transition. This method is strictly for internal use only and is not publicly available. Note that the getState() method is unneeded as a concrete state already knows what state it is.

Parameters:
aState - The new state to transition to.