PHP design pattern-appearance pattern

Source: Internet
Author: User
PHP design pattern-appearance pattern-structural pattern

Overview: provides a consistent interface for a group of interfaces in a subsystem. this mode defines a high-level interface, which makes this subsystem easier to use.

The appearance mode allows the client to call a complicated system in a simple way to accomplish one thing;

Purpose:

1. provides simple interfaces for a complex subsystem

2. reduce coupling between clients and subsystems

Personal example:

1. buy a hand-captured pie

Namespace haibao \ design \ web \ view \ design;

Use haibao \ design \ web \ common \ design \ adapter \ Translator;

Class Facade extends \ haibao \ design \ web \ view \ Base {

Protected function preRender (){

Header ("Content-type: text/html; charset = utf-8 ");

$ Facade = new \ haibao \ design \ web \ common \ design \ facade \ Facade ();

$ Facade-> facade1 ();

Echo'

';

$ Facade-> facade2 ();

}

}

/**

* Shopaholics capture cakes

*/

Namespace haibao \ design \ web \ common \ design \ facade;

Class Facade {

Public $ object1;

Public $ object2;

Public $ object3;

Public function _ construct (){

$ This-> object1 = new SubSystem1; // pie

$ This-> object2 = new SubSystem2; // Click

$ This-> object3 = new SubSystem3; // add a sausage

}

Public function facade1 (){

$ This-> object1-> getMessage ();

$ This-> object2-> getMessage ();

}

Public function facade2 (){

$ This-> object2-> getMessage ();

$ This-> object3-> getMessage ();

}

}

/**

* Subclass

*/

Namespace haibao \ design \ web \ common \ design \ facade;

Class SubSystem1 {

Public function getMessage (){

Echo 'subsystem 1 ';

}

}

/**

* Subclass

*/

Namespace haibao \ design \ web \ common \ design \ facade;

Class SubSystem2 {

Public function getMessage (){

Echo 'subsystem 2 ';

}

}

/**

* Subclass

*/

Namespace haibao \ design \ web \ common \ design \ facade;

Class SubSystem3 {

Public function getMessage (){

Echo 'subsystem 3 ';

}

}

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.