Listing 4 The Command pattern
#include <iostream> // base command class class Command { public: Command () {} ~Command () {} // the actual command logic resides in Execute () virtual void Execute () = 0; }; class Command_A : public Command { public: Command_A () {} ~Command_A () {} void Execute () { std::cout << "Doing some work" << std::endl; } }; class Command_B : public Command { public: Command_B () {} ~Command_B () {} void Execute () { std::cout << "Doing some other work" << std::endl; } }; int main () { Command_A a; Command_B b; Command* Commands[ 2 ]; Commands[ 0 ] = &a; Commands[ 1 ] = &b; Commands[ 0 ]->Execute (); Commands[ 1 ]->Execute (); return ( 0 ); }