Structure |
|
Intention |
Providing a consistent interface for a set of interfaces in a subsystem, the F a c a D e pattern defines a high-level interface that makes this subsystem easier to use. |
Applicability |
- When you want to provide a simple interface for a complex subsystem. Subsystems tend to become more complex as they evolve. Most patterns will produce more and smaller classes when used. This makes the subsystem more reusable and easier to customize the subsystem, but it also brings some usability difficulties to users who do not need to customize the subsystem. f a c a D e can provide a simple default view that is sufficient for most users, and those who need more customization can cross the f a c a D e layer.
- There is a large dependency between the client program and the implementation part of the abstract class. The introduction of f a c a D e separates the subsystem from the customer and other subsystems, which can improve the independence and portability of the subsystem.
- When you need to build a hierarchical subsystem, use the f a C a D e pattern to define the entry points for each layer in the subsystem. If subsystems are interdependent, you can make them communicate only through f a c a D e, simplifying the dependencies between them.
|
1 usingSystem;2 3 classSubsystem_class14 {5 Public voidOperationx ()6 {7Console.WriteLine ("Subsystem_class1. Operationx called");8 }9 }Ten One classSubsystem_class2 A { - Public voidOperationy () - { theConsole.WriteLine ("Subsystem_class2. Operationy called"); - } - } - + classSUBSYSTEM_CLASS3 - { + Public voidOperationz () A { atConsole.WriteLine ("SUBSYSTEM_CLASS3. Operationz called"); - } - } - - classfacade - { in PrivateSubsystem_class1 C1 =NewSubsystem_class1 (); - PrivateSubsystem_class2 C2 =NewSubsystem_class2 (); to PrivateSUBSYSTEM_CLASS3 C3 =NewSUBSYSTEM_CLASS3 (); + - Public voidOperationwrapper () the { *Console.WriteLine ("The facade Operationwrapper carries out complex decision-making"); $Console.WriteLine ("which in turn results on calls to the subsystem classes");Panax Notoginseng C1. Operationx (); - if(1==1 /*some really complex decision*/) the { + C2. Operationy (); A } the //lots of complex code here ... + C3. Operationz (); - } $ $ } - - /// <summary> the ///Summary description for Client. - /// </summary>Wuyi Public classClient the { - Public Static intMain (string[] args) Wu { -Facade facade =Newfacade (); AboutConsole.WriteLine ("Client calls the facade Operationwrapper"); $ facade. Operationwrapper (); - return 0; - } -}
appearance mode
Appearance mode of structural design pattern