Design Patterns---- Strategy 模式(二)

2014-11-24 10:52:35 · 作者: · 浏览: 1
shContext(){ if(pCashSuper_) delete pCashSuper_; } double GetResult(double money){ assert(pCashSuper_ != NULL); return pCashSuper_->acceptCash(money); } private: CashSuper *pCashSuper_; // copy not allowed CashContext(const CashContext&); CashContext& operator=(const CashContext&); }; // 客户端使用如下: CashContext csuper("满300减100"); cout << csuper.GetResult(300) << endl;



参考资料:

1. 大话设计模式

2. 设计模式:可复用面向对象软件的基础