1. Concepts
Provides a consistent interface for a group of interfaces in the subsystem. This mode defines a high-level interface, which makes the subsystem easier to use.
2. Model
Public class modulara {public void modularamethod () {console. writeline ("A module method. ") ;}} Public class modularb {public void modularbmethod () {console. writeline (" B module method. ") ;}} Public class modularc {public void modularcmethod () {console. writeline (" C module method. ") ;}} Public class facade {private modulara MDA; private modularb MDB; private modularc MDC; Public facade () {MDA = new modulara (); MDB = new modularb (); MDC = new modularc ();} public void facademethod () // This method is responsible for external contact {MDA. modularamethod (); MDB. modularbmethod (); MDC. modularcmethod ();}}
Client
// If you do not need the appearance mode, the client will call modulara, modularb, and modularc respectively, and the coupling will be strong. // Modulara MDA = new modulara (); // modularb MDB = new modularb (); // modularc MDC = new modularc (); // MDA. modularamethod (); // MDB. modularbmethod (); // MDC. modularcmethod (); // use the appearance mode. The client only cares about the facade method, and the sum of the methods is related to this class, reducing coupling. Facade FD = new facade (); FD. facademethod (); console. Readline ();
Result
In fact, this mode is often used when writing code. Sometimes, when writing a separate function module, there is such a class that is responsible for communicating with the outside world and accepting input parameters, it is also responsible for outgoing results. external users do not need to care about how the module is implemented. They often reference this class to input some values, and the class then transmits the results. As for how to implement the function, this module is involved. Therefore, the contact between this module and the outside world is reduced. If the internal algorithm of this module does not affect the operation of other modules, the result is incorrect. In addition, I usually write a separate module to write all the public classes in it in addition to the classes to interact with the outside world as internal, forcing the outside to access internal details.