/* A MacroCommandmanages a sequence of subcommands and provides operations for adding and removing subcommands. No explicit receiver is required, because the subcommands already define their receiver. */ class MacroCommand : public Command { public: MacroCommand(); virtual ~MacroCommand(); virtual void Add(Command*); virtual void Remove(Command*); virtual void Execute(); private: List* _cmds; }; /* The key to the MacroCommand is its Execute member function. This traverses all the subcommands and performs Execute on each of them. */ void MacroCommand::Execute () { ListIterator i(_cmds); for (i.First(); !i.IsDone(); i.Next()) { Command* c = i.CurrentItem(); c->Execute(); } } /* Note that should the MacroCommand implement an Unexecute operation, then its subcommands must be unexecuted in reverse order relative to Execute’s implementation. Finally, MacroCommand must provide operations to manage its subcommands. The MacroCommand is also responsible for deleting its subcommands. */ void MacroCommand::Add (Command* c) { _cmds->Append(c); } void MacroCommand::Remove (Command* c) { _cmds->Remove(c); }