Design Patterns in PHP--façade mode

Source: Internet
Author: User

Tag:php   interface    Object     design mode    

<?php/** (1) The appearance mode (facade) is also called the façade mode, which provides a consistent interface for a set of interfaces in the subsystem, which defines a high-level interface that makes the subsystem easier to use. Provide a set of interfaces (2) for some complex subsystems the main role façade (facade) role? Will this role be called by the client? Know which subsystems are responsible for processing requests? Assign the user's request to the appropriate subsystem subsystem (subsystem) role? Implement subsystem functions? Handle tasks assigned by the facade object? There is no facade related information, can be called directly by the client? You can have one or more subsystems at the same time, and each subsystem is not a separate class, but a collection of classes. Each subsystem can be called directly by the client, or by the façade role (3) Usage: First of all, in the initial stage of the design, you should be aware of the different two layers, such as the classic three-tier architecture, you need to consider the data access layer and the business logic layer, The layer and layer of the business logic layer and the presentation layer establish the appearance facade, which can provide a simple interface for the complex subsystem, so the coupling degree is greatly reduced. Second, in the development phase, subsystems tend to become more and more complex due to the evolution of continuous refactoring, most of the patterns used will produce a lot of very small classes, this is good, but also to the external call their user program brought difficulties in the use of, increase the appearance of facade can provide a simple interface, Reduce the dependency between them. Thirdly, when maintaining a large legacy system, it is possible that the system is very difficult to maintain and extend, but because it contains very important functions, new requirements development must depend on it. In this case, it is also very appropriate to facade with the appearance pattern. You can develop an appearance facade class for the new system that provides a clear, simple interface for designing rough or highly complex legacy code, allowing the new system to interact with facade objects, facade all the complex work of interacting with legacy code.    "(4) specific examples such as my shutdown, the whole process including turning off the monitor, shutting down the PC machine, power off, the button to shut down the role of the façade, the other for the subsystem *///façade abstract Interface interface facade{Public function turnOn (); Public function turnoff ();} (1) Turn off display class Pclight {public Function turnOn () {} public Function turnoff () {echo ' Turn off Pclight <br>   ' ;} }//(2) PC machineClass Pcmachine {public Function turnOn () {} public Function turnoff () {echo ' Turn off Pcmathion <br> ';}} (3) Power off class Power {public Function turnOn () {} public Function turnoff () {echo ' Turn off power <br> ';  }}//shutdown of the façade role class Pcfacade implements Facade{private $PcLight; private $Pcmachine; private $Power;         Public Function __construct () {$this->pclight = new Pclight ();         $this->pcmachine = new Pcmachine (); $this->power = new Power ();}          Application of the façade role public function turnoff () {$this->pclight->turnoff ();          $this->pcmachine->turnoff (); $this->power->turnoff (); } public Function TurnOn () {}}//applies $button = new Pcfacade (); $button->turnoff (); /* In fact, the façade mode is to put several subsystems (instances or classes.) Unified a unified interface to perform, the client does not care about the subsystem, only with the façade can be

Design Patterns in PHP--façade mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.