A typical application of Façade mode: socket interface
Socket and Transport layer TCP, UDP protocol, Network layer IP, ICMP protocol interaction, imagine if there is no socket this layer, we do not want to deal with TCP, UDP, IP, ICMP protocol,
In order to hide the complexity of the subsequent protocol, a socket was created.
Façade mode is a way for the client to make the subsystem more accessible by accessing the façade interface without having to access the specific subsystem.
Here is an application of the façade pattern:
public static void Main (string[] args) {
Normal call
A = new A ();
A.test ();
b b = new B ();
B.test (); //......
The problem with this is that the caller needs to understand all the subsystems
Façade mode
Fade Fade =new Fade ();
Fade.testa ();
Fade.testb ();
FADE.TESTC ();
Through the façade mode avoids the client to understand each subsystem
}
}
Class Fade {
public void TestA () {
A = new A ();
A.test ();
}
public void Testb () {
b b = new B ();
B.test ();
}
public void Testc () {
c C = new C ();
C.test ();
}
}
Class A {
public void Test () {System.out.println ("access a"); } }
Class B {
public void Test () {System.out.println ("Access B"); } }
Class C {
public void Test () {System.out.println ("Access C"); } }
Design mode----Façade mode