这篇文章主要介绍了php实现的简单适配器模式,结合具体实例形式分析了php适配器模式的实现技巧与调用方法,需要的朋友可以参考下
本文实例讲述了php实现的简单适配器模式。分享给大家供大家参考,具体如下:
<?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简单适配器模式的介绍的详细内容。
