<?php
/**
* @Description: 适配器模式
* @Author: luoxiaojin
* @Date: 2020-06-29 22:06:04
* @LastEditors: luoxiaojin
* @LastEditTime: 2020-06-30 10:09:29
* @FilePath: design_patternsl9.php
*/

适配器模式

// 天气预报,兼容新旧客户端和不同平台的解决方案

class Weather{
public static function show(){
$today = [‘temperature’=>’28℃’,’wind’=>5,’sun’=>’sunny’];
return serialize($today);
}
}

// print_r(unserialize((new Weather)->show()));

class AdapterWeather extends Weather{
public static function show(){
return json_encode(unserialize(parent::show()));
}
}

print_r(AdapterWeather::show());

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。