时间:2021-07-01 10:21:17 帮助过:40人阅读
具体如下:
<?php
//适配器模式-通过适配器去执行第三方方法
//定义目标接口
interface Target{
public function simpleMethod1();
public function simpleMethod2();
}
class Adatee{
public function simpleMethod1(){
echo 'Adatee simpleMethod1<br/>';
}
}
//类适配器模式
class Adapter implements Target{
private $adatee;
public function __construct(Adatee $adatee){
$this->adatee = $adatee;
}
public function simpleMethod1(){
echo $this->adatee->simpleMethod1();
}
public function simpleMethod2(){
echo $this->adatee->simpleMethod12();
}
}
//客户端接口
class Client{
public static function main(){
$adapter = new Adapter(new Adatee());
$adapter->simpleMethod1();
}
}
Client::main();PHP设计模式之 适配器模式
关于php设计模式-适配器的方法详解
PHP简单适配器模式的介绍
以上就是PHP实现适配器模式的方法详解的详细内容,更多请关注Gxl网其它相关文章!