#ifndef STATE_H #define STATE_H /////////////////////////////////////////////////////////////// // state.h - defines states in terms of the events // // that trigger transitions to another state // // // // ver 1.1 Adds hooks for new state // // Platform: Dell XPS 8920, Windows 10 // // Application: CSE776 - Design Patterns : State Pattern // // Author: Jim Fawcett, CST 2-187, (314) 443-3948 // // jfawcett@twcny.rr.com // /////////////////////////////////////////////////////////////// #include #include struct Context; class ElevBase { public: ElevBase* getRegistered(int n); ElevBase* getEvent(ElevBase *pState); virtual ElevBase* upButton() { return this; } // OnFirstFloor overrides virtual ElevBase* dnButton() { return this; } // OnSecondFloor overrides virtual ElevBase* arrived() { return this; } // GoingUp and GoingDown override virtual ElevBase* newEvent() { return this; } // BreakingCable overrides // this is a hook to add in new events static ElevBase* makeElevStates(); virtual ~ElevBase() = 0 // make this class abstract - note definition { std::cout << "\n destroying ElevBase abstract state"; } protected: static Context* pContext_; }; /////////////////////////////////////////////////////////////// // concrete state classes // /////////////////////////////////////////////////////////////// //----< on the first floor >----------------------------------- class OnFirstFloor : public ElevBase { public: virtual ~OnFirstFloor (); virtual ElevBase* upButton() override; static ElevBase* makeState(); }; //----< going up to second floor >----------------------------- class GoingUp : public ElevBase { public: virtual ~GoingUp(); virtual ElevBase* arrived() override; static ElevBase* makeState(); }; //----< on the second floor >---------------------------------- class OnSecondFloor : public ElevBase { public: virtual ~OnSecondFloor(); virtual ElevBase* dnButton() override; static ElevBase* makeState(); }; //----< going down to first floor >---------------------------- class GoingDown : public ElevBase { public: virtual ~GoingDown(); virtual ElevBase* arrived() override; static ElevBase* makeState(); }; #endif