当前位置 : 主页 > 网络编程 > PHP >

interface的使用和说明.php

来源:互联网 收集:自由互联 发布时间:2021-06-28
interface的使用和说明.php discount;}function getUserType(){return "VIP用户";}}//商品类class Goods{ var $price = 100; var $vc; //定义 User 接口类型参数,这时并不知道是什么用户 function run($vc){ $this-vc = $vc;
interface的使用和说明.php
 discount;
	}
	function getUserType(){
		return "VIP用户";
	}
}
//商品类
class Goods{
    var $price = 100;
    var $vc;
    //定义 User 接口类型参数,这时并不知道是什么用户
    function run($vc){
        $this->vc = $vc;
        $discount = $this->vc->getDiscount();
		$usertype = $this->vc->getUserType();
        echo $usertype."商品价格:".$this->price*$discount;
    }
}


//调用案例
$Goods = new Goods();
$Goods->run(new VipUser);	
?>
网友评论