<?php
/**
* @Description: 适配器模式
* @Author: luoxiaojin
* @Date: 2020-06-29 22:06:04
* @LastEditors: luoxiaojin
* @LastEditTime: 2020-06-30 10:09:29
* @FilePath: \design_patterns\l9.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());
评论前必须登录!
注册