Appearance mode: provides a consistent interface for a group of interfaces in the subsystem. This mode defines a high-level interface, which makes the system easier to use.
SubSystem Class sub-system Class sets implement sub-system functions to process the tasks assigned by the Facade object. Note that there is no Facade Information in the sub-Class, that is, there is no reference to the Facade object.
The first is the class of the four subsystems.
Public class SubSystemOne {public void MethodOne () {Console. writeLine ("Subsystem Method 1") ;}} public class SubSystemTwo {public void MethodTwo () {Console. writeLine ("Subsystem Method 2") ;}} public class SubSystemThree {public void MethodThree () {Console. writeLine ("Subsystem Method 3") ;}} public class SubSystemFour {public void MethodFour () {Console. writeLine ("Subsystem Method 4 ");}}
Appearance
Public 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 ("\ n method group A () ----"); one. methodOne (); two. methodTwo (); four. methodFour ();} public void MethodB () {Console. writeLine ("\ n method group B () ----"); two. methodTwo (); three. methodThree ();}}
Client call
class Program { static void Main(string[] args) { Facade facade = new Facade(); facade.MethodA(); facade.MethodB(); Console.ReadLine(); } }
The running result is as follows:
First, in the initial stage of design, we should consciously separate the two layers.
Second, in the development stage, subsystems are often increasingly complicated due to continuous reconstruction and evolution. Adding a Facade can provide a simple interface to reduce the dependency between them.
Third, it may be difficult to maintain and expand a legacy large system. A Facade class can be developed for the new system to provide clear and simple interfaces for designing rough or highly complex legacy code, so that the new system can interact with the Facade object, facade interacts with legacy code for all complex tasks.