zoukankan      html  css  js  c++  java
  • 【php设计模式】门面模式

    门面模式又叫外观模式,用来隐藏系统的复杂性,并向客户端提供了一个客户端可以访问系统的接口。这种类型的设计模式属于结构型模式,它向现有的系统添加一个接口,来隐藏系统的复杂性。

    这种模式涉及到一个单一的类,该类提供了客户端请求的简化方法和对现有系统类方法的委托调用。

    <?php
    
    interface Shape{
        public function draw();
    }
    
    class Circle implements Shape{
        public function draw(){
            echo "画一个圆形
    ";
        }
    }
    
    class Rectangle implements Shape{
        public function draw(){
            echo "画一个矩形
    ";
        }
    }
    
    class Square implements Shape{
        public function draw(){
            echo "画一个正方形
    ";
        }
    }
    
    class ShapeMark{
    
        public $circle;
        public $rectangle;
        public $square;
    
        public function __construct(){
            $this->circle = new Circle();
            $this->rectangle = new Rectangle();
            $this->square = new Square();
        }
    
        public function drawCircle(){
            $this->circle->draw();
        }
    
        public function drawRectangle(){
            $this->rectangle->draw();
        }
    
        public function drawSquare(){
            $this->square->draw();
        }
    }
    
    $shapemark = new shapemark();
    $shapemark->drawCircle();//画一个圆形
    $shapemark->drawRectangle();//画一个矩形
    $shapemark->drawSquare();//画一个正方形
  • 相关阅读:
    PyQt5笔记之标签
    PyQt5笔记之布局管理
    PyQt5笔记之菜单栏
    Windows环境安装PyQt5
    MySQL8的密码策略
    find命令常用参数
    Linux性能监控工具
    Linux内核管理
    DNS简单配置
    Solr 5.2.1 部署并索引Mysql数据库
  • 原文地址:https://www.cnblogs.com/itsuibi/p/11016019.html
Copyright © 2011-2022 走看看