设计模式之外观模式(PHP实现)
github地址:https://github.com/ZQCard/design_pattern
/**
* 外观模式(Facade Pattern)隐藏系统的复杂性,并向客户端提供了一个客户端可以访问系统的接口。
* 这种类型的设计模式属于结构型模式,它向现有的系统添加一个接口,来隐藏系统的复杂性。
* 这种模式涉及到一个单一的类,该类提供了客户端请求的简化方法和对现有系统类方法的委托调用。
*/
(1)Shape.class.php (接口类,规范实现类接口)
<?php namespace Facade; interface Shape
{
public function draw();
}
(2)Circle.class.php (圆形具体实现类)
<?php namespace Facade; class Circle implements Shape
{
public function draw()
{
print_r("CirCle");
}
}
(3)Square.class.php (正方形具体实现类)
<?php namespace Facade; class Square implements Shape
{
public function draw()
{
print_r("Square");
}
}
(4)Rectangle.class.php(长方形实现类)
<?php namespace Facade; class Rectangle implements Shape
{
public function draw()
{
print_r("Rectangle");
}
}
(5) ShapeFacade.class.php(形状门面装饰类)
<?php namespace Facade; class ShapeFacade
{
private $circle;
private $rectangle;
private $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();
}
}
(6)facade.php (客户端)
<?php
spl_autoload_register(function ($className){
$className = str_replace('\\','/',$className);
include $className.".class.php";
});
use Facade\ShapeFacade;
$shape = new ShapeFacade();
$shape->drawCircle();
设计模式之外观模式(PHP实现)的更多相关文章
- 每天一个设计模式-2 外观模式(Facade)
每天一个设计模式-2 外观模式(Facade) 1.生活中的示例 客户想要购买一台电脑,一般有两种方法: 1.自己DIY,客户需要知道组成电脑的所有电子器件,并且需要熟悉那些配件,对客户要求较高. ...
- C#设计模式(11)——外观模式(Facade Pattern)
一.引言 在软件开发过程中,客户端程序经常会与复杂系统的内部子系统进行耦合,从而导致客户端程序随着子系统的变化而变化,然而为了将复杂系统的内部子系统与客户端之间的依赖解耦,从而就有了外观模式,也称作 ...
- 乐在其中设计模式(C#) - 外观模式(Facade Pattern)
原文:乐在其中设计模式(C#) - 外观模式(Facade Pattern) [索引页][源码下载] 乐在其中设计模式(C#) - 外观模式(Facade Pattern) 作者:webabcd 介绍 ...
- 设计模式之 外观模式详解(Service第三者插足,让action与dao分手)
作者:zuoxiaolong8810(左潇龙),转载请注明出处,特别说明:本博文来自博主原博客,为保证新博客中博文的完整性,特复制到此留存,如需转载请注明新博客地址即可. 各位好,LZ今天给各位分享一 ...
- 8.4 GOF设计模式三: 外观模式 Facade
GOF设计模式三: 外观模式 Facade “现有系统”功能强大.复杂,开发“新系统”需要用到其中一部分,但又要增加一部 分新功能,该怎么办?4.1 Facade Pattern: Key Fea ...
- 北风设计模式课程---外观模式(Facade)总结
北风设计模式课程---外观模式(Facade)总结 一.总结 一句话总结: 不仅要通过视频学,还要看别的博客里面的介绍,搜讲解,搜作用,搜实例 设计模式都是对生活的抽象,比如用户获得装备,我可以先装备 ...
- js设计模式——2.外观模式
js设计模式——2.外观模式
- python设计模式之外观模式
python设计模式之外观模式 系统会随着演化变得非常复杂,最终形成大量的(并且有时是令人迷惑的)类和交互,这种情况并不少见.许多情况下,我们并不想把这种复杂性暴露给客户端.外观设计模式有助于隐藏系统 ...
- java设计模式之外观模式(门面模式)
针对外观模式,在项目开发和实际运用中十分频繁,但是其极易理解,下面就简要介绍一下. 一.概念介绍 外观模式(Facade),他隐藏了系统的复杂性,并向客户端提供了一个可以访问系统的接口.这种类型的设计 ...
- 【GOF23设计模式】外观模式
来源:http://www.bjsxt.com/ 一.[GOF23设计模式]_外观模式.公司注册流程.迪米特法则 package com.test.facade; public interface 工 ...
随机推荐
- MySQL常用客户端 命令
登录MySQL mysql -h localhost -uroot -p 授权指定用户访问指定数据库 GRANT ALL ON cookbook.* TO 'cbuser'@'localhost' I ...
- nio的reactor模式
转自:http://blog.csdn.net/it_man/article/details/38417761 线程状态转换图 就是非阻塞IO 采用多路分发方式举个例子吧,你服务器做一个聊天室,按照以 ...
- Swift中由找不到removeAll(where:)方法引起的连锁反应(上)
核心代码 section.removeAll {baseRow in if let habitRow = baseRow as? HabitRow{ let idxPath = habitRow.in ...
- 2017 多校5 Rikka with String
2017 多校5 Rikka with String(ac自动机+dp) 题意: Yuta has \(n\) \(01\) strings \(s_i\), and he wants to know ...
- chrome性能指标(TTFB,TTSR,TTDC,TTFL)
1.TTFB (Time To First Byte) 是最初的网络请求被发起到从服务器接收到第一个字节这段时间,它包含了 TCP连接时间,发送HTTP请求时间和获得响应消息第一个字节的时间. 注意: ...
- Codeforces Round #355 (Div. 2) C 预处理
C. Vanya and Label time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces 932.A Palindromic Supersequence
A. Palindromic Supersequence time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Avito Cool Challenge 2018 :E. Missing Numbers
E. Missing Numbers 题目链接:https://codeforces.com/contest/1081/problem/E 题意: 现在有n个数(n为偶数),但只给出a2,a4.... ...
- Cisco IPC Emergency Responder Error
Upon startup of the newer Cisco IP Communicator clients (especially on Windows Vista/7), sometimes y ...
- 转:Android Log
在调试代码的时候我们需要查看调试信息,那我们就需要用Android Log类. android.util.Log常用的方法有以下5个:Log.v() Log.d() Log.i() Log.w() 以 ...