标签:cli UNC interface actor code click 依赖 php xxx
目标:创建有依赖关系的实例;(套餐)
<?php //抽象类 食物 interface IAllayFood { function Allay(); } interface IDrinkFood { function Drink(); }
<?php //抽象类 获取食物 --》客户 interface Ifactorys { function getAllayFood(); function getDrinckFood(); }
<?php include "D:\\xxxx\cx_gc.php"; class Afactory implements Ifactorys { function getAllayFood() { return new hanbao(); } function getDrinckFood() { return new coco(); } } class Bfactory implements Ifactorys { function getAllayFood() { return new chicken(); } function getDrinckFood() { return new baishi(); } }
<?php include "D:\\xxxx\cp_cx.php"; class chicken implements IAllayFood { function Allay() { echo ‘鸡肉给小妹妹解饿‘."<br/>"; } } class hanbao implements IAllayFood { function Allay() { echo ‘汉堡给小妹妹解饿‘."<br/>"; } } class coco implements IDrinkFood { function Drink() { echo ‘可口可乐给小妹妹解饿‘."<br/>"; } } class baishi implements IDrinkFood { function Drink() { echo ‘百世可乐给小妹妹解饿‘."<br/>"; } }
<?php require "./jt_sl.php"; require "./jt_gc.php"; $a = new Afactory(); $b = new Bfactory(); $achi = $a->getAllayFood()->Allay(); $ahe = $a->getDrinckFood()->Drink(); //print_r($ahe);die; $achi = $b->getAllayFood()->Allay(); $ahe = $b->getDrinckFood()->Drink();
标签:cli UNC interface actor code click 依赖 php xxx
原文地址:https://www.cnblogs.com/songyanan/p/11963688.html