#ifndef COMMAND_H #define COMMAND_H /////////////////////////////////////////////////////////////// // command.h - declare command and invoker classes // // ver 1.0 // // Lanuage: Visual C++, ver 6.0 // // Platform: Micron Dual Pentium Pro 200, Win NT 4.0 // // Application: CSE791 - Design Patterns Example // // Author: Jim Fawcett, Instructor // // CST 2-187, (315) 443-3948 // // fawcett@ecs.syr.edu // /////////////////////////////////////////////////////////////// #include class command; /////////////////////////////////////////////////////////////// // invoker is usually some, perhaps large, library facility // // that generates events clients need to react to // /////////////////////////////////////////////////////////////// class invoker { public: enum events { firstEv, secondEv, thirdEv }; void Register(command*); void doCommands(events event); void doEvents(); private: std::vector registrants; }; /////////////////////////////////////////////////////////////// // command defines some interface for executing client code // // when one of perhaps several special events occurs // /////////////////////////////////////////////////////////////// class command { public: virtual void execute(invoker::events event) = 0; }; // /////////////////////////////////////////////////////////////// // this function will stay about the same for any library // /////////////////////////////////////////////////////////////// inline void invoker::Register(command* pComm) { registrants.push_back(pComm); } /////////////////////////////////////////////////////////////// // this function will stay about the same for any library // /////////////////////////////////////////////////////////////// inline void invoker::doCommands(events event) { unsigned int i; for(i=0; iexecute(event); } /////////////////////////////////////////////////////////////// // this function represents processing that will change for // // each library // /////////////////////////////////////////////////////////////// inline void invoker::doEvents() { doCommands(firstEv); doCommands(secondEv); doCommands(thirdEv); } #endif