<?php
header('Content-Type:text/html; charset=utf-8');
interface USB{
function mount();
function work();
function unmount();
}
class worker{
function install(){//载入外设
//首先获取电脑
$cm=new computer;
//然后获取外设
//$usb=new kingsoft;//多态性 显露无疑 统一父类接口 不同输出效果
$usb=new mouse;
//然后调用函数useUSB
$cm->useUSB($usb);
}
}
//创建电脑类
class computer{
//电脑类应该有对应处理外设的函数
function useUSB($usb){//电脑外设对(函数)反应
$usb->mount();
$usb->work();
$usb->unmount();
}
}
//外设类
class kingsoft implements USB{
function mount(){
echo "开始挂载<br/>";
}
function work(){
echo "开始工作<br/>";
}
function unmount(){
echo "开始卸载<br/>";
}
}
class mouse implements USB{
function mount(){
echo "鼠标开始载入驱动==>lodging...<hr/>";
}
function work(){
echo "鼠标开始正常工作<hr/>";
}
function unmount(){
echo "鼠标结束工作被拔出===>out...<hr/>";
}
}
$worker=new worker;
$worker->install();