<?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());
点击 "运行实例" 按钮查看在线实例
——学习参考与 bilibili燕十八 面向对象与设计模式