php面向接口编程
来源:互联网 发布:魔兽数据库7.0手机 编辑:程序博客网 时间:2024/06/09 14:33
<?php//定义接口interface User{ function getDiscount(); function getUserType();}//VIP用户 接口实现class VipUser implements User{ // VIP 用户折扣系数 private $discount = 0.8; function getDiscount() { return $this->discount; } function getUserType() { return "VIP用户"; }}class Goods{ var $price = 100; var $vc; //定义 User 接口类型参数,这时并不知道是什么用户 function run(User $vc){ $this->vc = $vc; $discount = $this->vc->getDiscount();$usertype = $this->vc->getUserType(); echo $usertype."商品价格:".$this->price*$discount; }}$display = new Goods();$display ->run(new VipUser);//可以是更多其他用户类型?>
0 0
- php面向接口编程
- php面向对象编程--接口
- php面向对象编程--多态性之接口
- php面向对象编程:抽象类与接口的区别
- PHP面向对象-接口。
- 面向接口 的编程
- 面向接口的编程
- 面向接口编程(摘)
- 面向接口编程
- 面向接口编程详解
- 面向接口编程
- 面向接口编程
- 面向接口的编程
- 小议面向接口编程
- 面向接口编程知识
- java面向接口编程
- 面向接口编程详解
- 面向接口编程
- 百度地图marker
- Ubuntu中Mysql中文存储乱码设置问题
- 属性动画Demo
- POJ2404:Jogging Trails
- Android透明度换算
- php面向接口编程
- Spring的FactoryBean的基本认识
- 抓包工具Fiddler的使用教程(二十):深入研究AutoResponder
- 最全最好用的Android Studio插件整理
- phpcms v9 本地安装(upupw)
- framework 与 Settings 模块
- 性能测试总结—测试流程篇
- componentsJoinedByString 转化的字符串存储到数据库内部后,显示一个口
- strcpy strncpy实验