Design Mode - Appearance Mode

Appearance Mode



1. Definition

Facade mode provides a concise and consistent interface for various types (or structures and methods) in the subsystem, hides the complexity of the subsystem and makes the subsystem easier to use


2. Structure

Facade role: Clients can call the methods of this role. This role is aware of the functions and responsibilities of the associated subsystem(s). Under normal circumstances, this role will delegate all requests from the client to the corresponding subsystem.
Subsystem (SubSystem) role: There can be one or more subsystems at the same time. Each subsystem is not a separate class, but a collection of classes (for example, the above subsystem is composed of three classes, SystemA, SystemB, and SystemC). Each subsystem can be called directly by the client, or by the facade role. The subsystem does not know the existence of the facade, and to the subsystem, the facade is just another client.




3. Case

//SubSystem (SubSystem) role
public class SystemA{
public void doA(){
System.out.println("Subsystem A function");
}
}


//Subsystem (SubSystem) role
public class System{
public void doB (){
System.out.println("Function of Subsystem B");
}
}


//Subsystem (SubSystem role)
public class SystemC{
public void doC(){
System.out.printoln("Function of Subsystem C ");
}
}

/*
*Facade role
*/

public class Facade{
private SystemA systemA;
private SystemB systemB;
private SystemC systemC; Facade(){ systemA=new SystemA(); systemB=new SystemB();




systemC=new SystemC();
}
//The method meets the function required by the client
public void doAB(){
systemA.doA();
systemB.doB();
}
//The method meets the function required by the client
public void doABC() {
systemA.doA();
systemB.doB();
systemC.doC();
}
}


//Client
public class Client{
public static void mian(String[] args){
Facade f = new Facade();
System. out.println("two subsystem functions required by customer 1");
f.doAB();
System.out.println("three subsystem functions required by customer 2");
f.doABC
}
}



result: 

Two subsystems function required by client 1 Function 
of subsystem A Function of 
subsystem B Function of three subsystems required by
client  2 Function of
subsystem A Function of 
subsystem B Function of 
subsystem C Function of subsystem C




1. Appearance mode provides complex subsystems A simple interface is provided, and new functions and behaviors are not added to the subsystem.
2. The appearance pattern realizes the loose coupling relationship between the subsystem and the client.
3. The appearance mode does not encapsulate the subsystem class, but only provides a simple interface. It does not restrict clients to use subsystem classes if required by the application. It is thus possible to choose between ease of use and versatility of the system.
4. The appearance mode focuses on simplifying the interface. It is more often seen from the level of the architecture to see the entire system, rather than the level of a single class.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325567710&siteId=291194637