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();//画一个正方形
  • 相关阅读:
    Ubuntu环境下IPython的搭建和使用
    智能移动导游解决方案简介
    企业文化、团队文化与知识共享
    CoinPunk项目介绍
    Insight API开源项目介绍
    比特币Bitcoin源代码安装编译
    Javascript单元测试Unit Testing之QUnit
    Node.js的UnitTest单元测试
    Node.js调试
    Alfresco 4 项目介绍
  • 原文地址:https://www.cnblogs.com/itsuibi/p/11016019.html
Copyright © 2011-2022 走看看