Blogger Information
Blog 11
fans 0
comment 0
visits 6598
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP设计模式学习笔记——适配器模式
青Blue的博客
Original
659 people have browsed it

实例

<?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燕十八 面向对象与设计模式

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post