/////////////////////////////////////////////////////////////////// // client.cpp - demonstrate command pattern // // ver 1.1 // // // // Participants are: // // command - provides interface for invoker to use commands // // concreteCommand - implements command interface // // invoker - notifies clients of events using commands // // receiver - receives the action of a command // // client - creates receivers, concrete commands, invoker // // // // Language: Visual C++, ver 7.1 // // Platform: Dell Dimension 8300, Windows XP, Pro, sp2 // // Application: CSE776 - Design Patterns, Summer 2005 // // Author: Jim Fawcett, Instructor // // CST 2-187, (315) 443-3948 // // jfawcett@twcny.rr.com // /////////////////////////////////////////////////////////////////// #include #include "receiver.h" #include "concreteCommand.h" using namespace std; void main() { cout << "\n Demonstrate Command Pattern " << "\n ============================="; /////////////////////////////////////////////////////////////// // create concrete commands, passing them any information // // needed for their execute functions // /////////////////////////////////////////////////////////////// receiver r1("receiver r1"); receiver r2("receiver r2"); concreteCommand1 comm1(r1); concreteCommand2 comm2(r2); /////////////////////////////////////////////////////////////// // any client can register interest in library events // /////////////////////////////////////////////////////////////// invoker inv; inv.Register(invoker::event1,&comm1); // client #1 inv.Register(invoker::event2,&comm1); // client #1 inv.Register(invoker::event2,&comm2); // client #2 inv.Register(invoker::event3,&comm2); // client #2 /////////////////////////////////////////////////////////////// // use the library facilities // /////////////////////////////////////////////////////////////// inv.doEvents(); // clients get notified here cout << endl << endl; }