zoukankan      html  css  js  c++  java
  • PHP策略设计模式

    '; } } /** * 具体策略角色B */ class ConcreteStrategyB implements Strategy { public function algorithmInterface() { echo 'algorithmInterface B
    '; } } /** * 具体策略角色C */ class ConcreteStrategyC implements Strategy { public function algorithmInterface() { echo 'algorithmInterface C
    '; } } /** * 环境角色 */ class Context { /* 引用的策略 */ private $_strategy; public function __construct(Strategy $strategy) { $this->_strategy = $strategy; } public function contextInterface() { $this->_strategy->algorithmInterface(); } } /** * 客户端 */ class Client { /** * Main program. */ public static function main() { $strategyA = new ConcreteStrategyA(); $context = new Context($strategyA); $context->contextInterface(); $strategyB = new ConcreteStrategyB(); $context = new Context($strategyB); $context->contextInterface(); $strategyC = new ConcreteStrategyC(); $context = new Context($strategyC); $context->contextInterface(); } } Client::main(); ?>

    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
    更多技术文章请搜索千锋PHP,做真实的自己,用良心做教育。
    互联网+时代,时刻要保持学习,携手千锋PHP,Dream It Possible。

  • 相关阅读:
    hdoj1587
    欧拉定理及其应用
    hdoj1571
    hdoj1050
    POJ推荐50题
    poj2593
    hdoj1286
    hdoj1215七夕节
    我的Linux软件
    ACM题目推荐--《算法艺术与信息学竞赛》(转)
  • 原文地址:https://www.cnblogs.com/lhbryant/p/6929231.html
Copyright © 2011-2022 走看看