您的当前位置:首页>全部文章>文章详情

php设计模式之适配器模式(Adapter)

发表于:2019-08-16 10:25:32浏览:67次TAG:
这种模式允许使用不同的接口重构某个类,可以允许使用不同的调用方式进行调用。 #### 方式一 ```php _adaptee = $adaptee; } public function sampleMethod1() { $this->_adaptee->sampleMethod1(); } public function sampleMethod2() { var_dump('--------------'); } } $adapter = new Adapter(new Adaptee()); $adapter->sampleMethod1(); // string(14) "++++++++++++++" $adapter->sampleMethod2(); // string(14) "--------------" ?> ``` #### 方式二 ```php sampleMethod1(); // string(14) "++++++++++++++" $_adapter->sampleMethod2(); // string(13) "--------------" ?> ``` 输出 ```bash vagrant@vagrant-ubuntu:~$ sudo php adapter.php string(14) "++++++++++++++" string(13) "--------------" ```
栏目分类全部>
腾讯云采购季云服务器一折促销