门面模式又叫外观模式,用来隐藏系统的复杂性,并向客户端提供了一个客户端能够访问系统的接口。这种类型的设计模式属于结构型模式,它向现有的系统添加一个接口,来隐藏系统的复杂性。php
这种模式涉及到一个单一的类,该类提供了客户端请求的简化方法和对现有系统类方法的委托调用。设计模式
<?php interface Shape{ public function draw(); } class Circle implements Shape{ public function draw(){ echo "画一个圆形\n"; } } class Rectangle implements Shape{ public function draw(){ echo "画一个矩形\n"; } } class Square implements Shape{ public function draw(){ echo "画一个正方形\n"; } } 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();//画一个正方形