1. In the initial stage of design, we should consciously separate different two layers, for example, considering the establishment of a visual mode between the data access layer, business logic layer, and presentation layer, in this way, a simple and consistent interface can be provided for the subsystem, greatly reducing coupling.
2. In the development phase, the subsystem is very complicated because of not enough reconstruction. Increasing the appearance mode can shield this complexity and provide simple interfaces.
3. Maintain a legacy large system. When the code is difficult to maintain, the appearance mode is also a good choice.
Look at the structure of the appearance mode:
Facade class definition: Provides simple interfaces for high-level SystemsCopy codeThe Code is as follows: class Facade
{
SubSystemOne one;
SubSystemTwo two;
SubSystemThree three;
SubSystemFour four;
Public Facade ()
{
One = new SubSystemOne ();
Two = new SubSystemTwo ();
Three = new SubSystemThree ();
Four = new SubSystemFour ();
}
Public void MethodA ()
{
Console. WriteLine ("MethodA Combination Method ");
One. MethodOne ();
Two. MethodOne ();
}
Public void MethodB ()
{
Console. WriteLine ("MethodB Combination Method ");
Three. MethodOne ();
Four. MethodOne ();
}
}
SubSystemOne class: the underlying system is integrated with simple interfaces by the Facade class.Copy codeThe Code is as follows: class SubSystemOne
{
Public void MethodOne ()
{
Console. WriteLine ("Subsystem Method 1 ");
}
}
Main function call:Copy codeThe Code is as follows: class Program
{
Static void Main (string [] args)
{
Facade facade = new Facade ();
Facade. MethodA ();
Facade. MethodB ();
Console. ReadKey ();
}
}