实例
<?php /** * @Description: 多态性 * @Author: luoxiaojin * @Date: 2020-06-29 11:46:10 * @LastEditors: luoxiaojin * @LastEditTime: 2020-06-29 16:44:24 * @FilePath: \design_patterns\l1.php */ abstract class Tiger { abstract public function climb(); } class XTiger extends Tiger { public function climb() { echo "掉下来"; } } class MTiger extends Tiger { public function climb() { echo "爬到树顶"; } } class Cat { public function climb() { echo "飞起"; } } class Client { public static function call(Tiger $animal) { $animal->climb(); } } Client::call(new XTiger); Client::call(new MTiger); // Client::call(new Cat);
运行实例 »
点击 "运行实例" 按钮查看在线实例
——学习参考与 bilibili燕十八 面向对象与设计模式