| 
                         class VipUser implements People{ //实现接口 
//用户折卡系数 
private $discount=0.8; 
function getUserType(){ 
return "VIP用户"; 
} 
function getCount(){ 
return $this->discount; 
} 
} 
$vip=new VipUser(); //实现化对象 
echo $vip->getUserType().'商品价格:'.$vip->getCount()*100; //VIP用户商品价格:80 
class Goods{ 
var $price=100; 
var $member; 
function run(People $member){ //注意:这里面的参数类型是接口类型 
$this->member=$member; 
$discount=$this->member->getCount(); 
$usertype=$this->member->getUserType(); 
echo $usertype."商品价格:".$this->price*$discount; 
} 
} 
$display=new Goods(); 
$display->run(new VipUser);//VIP用户商品价格:80 
?> 
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如有疑问大家可以留言交流,谢谢大家对编程之家的支持。
                         (编辑:滁州站长网) 
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! 
                     |