/** * state.h * Implemented by Blueprint Technologies, Inc. */ #ifndef _state_h #define _state_h /** * Defines an interface for encapsulating the behavior * associated with a particular state of the Context. */ class State { public: virtual void handle() = 0; }; /** * Each subclass implements a behavior associated * with a state of the Context. */ class ConcreteStateA: public State { public: virtual void handle() { }; }; /** * Each subclass implements a behavior associated * with a state of the Context. */ class ConcreteStateB: public State { public: virtual void handle() { }; }; /** * Defines the interface of interest to clients. Maintains * an instance of a ConcreteState subclass that defines the * current state. */ class Context { private: State* state; public: Context(): state(0) { }; void request() { if( state ) { state -> handle(); } }; State* getState() { return state; }; void setState( State* state ) { this -> state = state; }; }; #endif