<?php /** **适配器模式:将需要把一类对象转化成另一类对象 **把源接口转化为目标接口 **适用范围:1.存在一个类,你想应用,接口却不是你想要的 **2. ****/ //目标接口 interface Target{ public function simpleFunction1(); public function simpleFunction2(); } //源接口 class Adaptee{ public function simpleFunction1(){ echo ‘simpleFunction1‘; } } //适配器类 class Adapter implements Target{ private $adaptee; public function __construct(Adaptee $adaptee){ $this->adaptee=$adaptee; } public function simpleFunction1(){ echo $this->adaptee->simpleFunction1(); } public function simpleFunction2(){ echo ‘Adapter Simple ‘; } } class client{ public static function main(){ $adaptee = new Adaptee(); $adapter = new Adapter($adaptee); $adapter->simpleFunction1(); $adapter->simpleFunction2(); } } client::main();
本文出自 “王尼美的成人之路” 博客,请务必保留此出处http://8335914.blog.51cto.com/8325914/1611168
原文:http://8335914.blog.51cto.com/8325914/1611168