Pattern Definition: Appearance mode (façade pattern): External communication with a subsystem must be carried out through a uniform visual object, providing a consistent interface for a set of interfaces in the subsystem, and the appearance pattern defines a high-level interface that makes the subsystem easier to use. The appearance pattern, also known as the façade mode, is an object-structured pattern.
Pattern structure:
The appearance pattern is to allow client clients to invoke a more complex system in a simple way to accomplish one thing.
SUBSYSTEM:
Copy Code code as follows:
Class Car {
Public Function Start () {
Print_r ("car Start");
}
Public Function Check_stop () {
Print_r ("Brake check normal");
}
Public Function Check_box () {
Print_r ("Check oil tank normal");
}
Public Function Check_console () {
Print_r ("Check if the dashboard is abnormal");
}
}
Facade mode
Class Carfacade {
Public function Catgo (car $carref) {
$carref->check_stop ();
$carref->check_box ();
$carref->check_console ();
$carref->start ();
}
}
The client can simply go to the call.
$car = new car ();
$CAROBJ = new Carfacade ();
$CAROBJ->catgo ($car);
Copy Code code as follows:
<?php
/**
* Sample Appearance mode
*
* Provides a consistent interface for a set of interfaces in a subsystem, defining a high-level interface that makes this subsystem easier to use
*/
Class SubSytem1
{
Public Function Method1 ()
{
echo "Subsystem1 method1<br/>";
}
}
Class SUBSYTEM2
{
Public Function Method2 ()
{
echo "Subsystem2 method2<br/>";
}
}
Class SubSytem3
{
Public Function Method3 ()
{
echo "Subsystem3 method3<br/>";
}
}
Class Façade
{
Private $_object1 = null;
Private $_object2 = null;
Private $_object3 = null;
Public Function __construct ()
{
$this->_object1 = new SubSytem1 ();
$this->_object2 = new SubSytem2 ();
$this->_object3 = new SubSytem3 ();
}
Public Function MethodA () {
echo "Façade methoda<br/>";
$this->_object1->method1 ();
$this->_object2->method2 ();
}
Public Function MethodB () {
echo "Façade methodb<br/>";
$this->_object2->method2 ();
$this->_object3->method3 ();
}
}
Instantiation of
$objFacade = new façade ();
$objFacade->methoda ();
$objFacade->methodb ();