您当前的位置:首页 > php > php抽象多态的应用
php抽象多态的应用
日期:2020-10-26 04:24:14 浏览:216
<?php
//多态
//接口中定义的方法必须全部实现
interface USB{
function load();
function using();
function uninstall();
}
class Keyboard implements USB{
public function load()
{
// TODO: Implement cd() method.
echo "键盘加载<br>";
}
public function using()
{
// TODO: Implement using() method.
echo "键盘使用中<br>";
}
public function uninstall()
{
// TODO: Implement uninstall() method.
echo "键盘卸载中<br>";
}
}
class mouse implements USB{
public function load()
{
// TODO: Implement cd() method.
echo "鼠标加载<br>";
}
public function using()
{
// TODO: Implement using() method.
echo "鼠标使用中<br>";
}
public function uninstall()
{
// TODO: Implement uninstall() method.
echo "鼠标卸载中<br>";
}
}
class Computer{
function load(USB $usb){
$usb->load();
$usb->using();
$usb->uninstall();
}
}
//$a=new Keyup();
//$a->load();
$b=new Computer();
$b->load(new Keyboard());
echo "<hr/>";
$c=new Computer();
$c->load(new mouse());