<?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());

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注