zoukankan      html  css  js  c++  java
  • 适配器模式

    1 <?php
     2 //适配器模式-通过适配器去执行第三方方法
     3 
     4 //定义目标接口
     5 interface Target{
     6     public function simpleMethod1();
     7     public function simpleMethod2();
     8 }
     9 
    10 class Adatee{
    11     public function simpleMethod1(){
    12         echo 'Adatee simpleMethod1<br/>';
    13     }
    14 }
    15 
    16 //类适配器模式
    17 class Adapter implements Target{
    18     private $adatee;
    19     public function __construct(Adatee $adatee){
    20         $this->adatee = $adatee;
    21     }
    22     public function simpleMethod1(){
    23         echo $this->adatee->simpleMethod1();
    24     }
    25     public function simpleMethod2(){
    26         echo $this->adatee->simpleMethod12();        
    27     }
    28 }
    29 
    30 //客户端接口
    31 class Client{
    32     public static function main(){
    33         $adapter = new Adapter(new Adatee());
    34         $adapter->simpleMethod1();
    35         
    36     }
    37 }
    38 Client::main();
  • 相关阅读:
    示波器测量电源的纹波
    hdoj 2717 Catch That Cow
    hdoj 1548 A strange lift
    hdoj 4586 Play the Dice
    zoj 2095 Divisor Summation
    hdoj 4704 Sum
    router-link传参
    字体自适应
    横向滚动div
    vue路由
  • 原文地址:https://www.cnblogs.com/yulei126/p/6786095.html
Copyright © 2011-2022 走看看