php 设计模式 --适配器
1,目标;实现一个不同的类不同方法,符合一定的规范;
规范类
<?php interface Iplay{ function Attack(); function Defence(); } class qianfeng implements Iplay { function Attack() { echo "麦迪干拔"; } function Defence() { echo "麦迪抢断一条龙"; } }
不规范类
<?php class yao{ function jg(){ echo "姚明批扣"; } function fs(){ echo "姚明顶板大帽"; } }
实现
<?php include "D:\\xxx\\huo.php"; include "D:\\xxx\\yao.php"; $qianfen = new qianfeng(); $qianfen->Attack(); echo "<br>"; $qianfen->Defence();$yao = new yao(); $yao->jg(); echo "<br>"; $yao->fs();class shipei implements Iplay{ private static $ym ; function __construct() { self::$ym = new yao(); } function Attack() { echo self::$ym->jg() ; } function Defence() { echo self::$ym->fs(); } } $shipei = new shipei(); $shipei->Attack(); echo "<br>"; $shipei->Defence();
主要理解思想