本文共 2573 字,大约阅读时间需要 8 分钟。
class CommandAction {public: virtual void Execute ();};class SaveAction : public CommandAction {public: virtual void Execute ();};class BackupAction : public CommandAction {public: virtual void Execute ();};class SendAction : public CommandAction {public: virtual void Execute ();};......
class CommandAction {public: virtual void Execute ();};class Composite1: public CommandAction {public: ...... virtual void Execute () { mSave->Execute(); mBackup->Execute(); }private: SaveAction* mSave; BackupAction * mBackup; };
class CommandAction {public: virtual void Execute() = 0; virtual void AddAction(CommandAction* action); virtual void DeleteAction(CommandAction* action);};class CompositeAction : public CommandAction {public: ...... virtual void Execute() { list::iterator it; for (it = mCompositor.begin(); it != mCompositor.end(); it++) { if (*it != NULL) { (*it)->Execute(pack); } } } virtual void AddAction(CommandAction* action) { if (action != NULL) { mCompositor.push_back(action); } } virtual void DeleteAction(CommandAction* action) { list ::iterator it; if (action != NULL) { for (it = mCompositor.begin(); it != mCompositor.end(); it++) { if (*it == action) { mCompositor.erase(it); break; } } }private: list mCompositor;};
转载地址:http://kceqj.baihongyu.com/