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

    <?php
    //适配器模式
    class tianqi {
        public static function show(){
            $today = ['tep' => 28,'wind' =>7,'sun' => 'sunny'];
            return serialize($today);
        }
    }
    
    //适配器
    class AdapterTianqi extends tianqi {
        public static function show(){
            $today = unserialize(parent::show());
            $today = json_encode($today);
            return $today;
        }
    }
    
    $tq = unserialize(tianqi::show());
    echo '温度:' . $tq['tep'] . '<br />';
    echo '风力:' . $tq['wind'] . '<br />';
    echo 'sun:' . $tq['sun'] . '<br />';
    
    
    echo '<br />php仿其他语言调用<br />';
    //java,python通过适配器调用
    $tq = AdapterTianqi::show();
    $tq = json_decode($tq,true);
    echo '温度:' . $tq['tep'] . '<br />';
    echo '风力:' . $tq['wind'] . '<br />';
    echo 'sun:' . $tq['sun'] . '<br />';
  • 相关阅读:
    第三次作业
    最后一次作业
    第14.15周作业
    第七周作业
    第六周作业
    第四周作业
    第三周作业
    第二周作业
    第一周作业
    第0次作业
  • 原文地址:https://www.cnblogs.com/nr-zhang/p/10950332.html
Copyright © 2011-2022 走看看