php设计模式之多态实例代码

<?php
header("Content-type:text/html;charset=utf-8");
/**
* 虎
*/
abstract class Tiger
{
    
    public abstract function climb();
}

/**
* x虎
*/
class Xtiger extends Tiger
{
    public function climb()
    {
        echo "摔下来<br>";
    }
}
/**
* m虎
*/
class Mtiger extends Tiger
{
    public function climb()
    {
        echo "爬上去树顶<br>";
    }
}

/**
* 客户端
*/
class Client
{
    
    public static function call(Tiger $animal)
    {
        $animal->climb();
    }
}

Client::call(new Xtiger());
Client::call(new Mtiger());
Client::call(new Mtiger());
Client::call(new Mtiger());
posted @ 2020-01-11 19:59  A毛毛  阅读(140)  评论(0编辑  收藏  举报