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

    <?php
    header("Content-type: text/html; charset=utf-8"); 
    class northcook{
        public function fan(){
            return '面条';
        }
        public function cai(){
            return '炒菜';
        }
        public function tang(){
            return '蛋花汤';
        }
    }
    class southcook{
        public function fan(){
            return '米饭';
        }
        public function cai(){
            return '烧菜+奶油';
        }
        public function tang(){
            return '海鲜汤';
        }
    }
    class fd{
        protected $fancreator=null;
        protected $caicreator=null;
        protected $tangcreator=null;
        public  function __construct($f,$c,$t){
            $this->fancreator=$f;
            $this->caicreator=$c;
            $this->tangcreator=$t;
        }
    public function createfan(){
        return $this->fancreator->fan();
    }
    public function createcai(){
        return $this->caicreator->cai();
    }
    public function createtang(){
        return $this->tangcreator->tang();
    }
    }
    $fd=new fd(new northcook,new northcook,new southcook);
    echo $fd->createfan();
    echo $fd->createtang();//输出“面条海鲜汤”
  • 相关阅读:
    python基础#1
    shell脚本基础练习题
    shell计算100以内加法
    shell脚本添加用户
    python学习ing
    框架
    前端
    python基础之数据类型-面向对象
    python四种列表的插入方法及其效率
    Charles高阶操作
  • 原文地址:https://www.cnblogs.com/aten/p/8422323.html
Copyright © 2011-2022 走看看