In practical application, the original code involved in multiple subsystems, re-design of the class, the original distributed in the source of the class structure and methods of re-assembly, the formation of a new, unified interface for the upper application use. Facade is often confronted with multiple classes or other program units that provide a unified interface/interface through the re-grouping of various and program units. Use facade mode when you encounter the following conditions: 1, 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 sub-system 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. Facade can provide a simple default view that is sufficient for most users, and those who need more customization can cross the facade layer. 2. There is a great dependence between the client program and the implementation part of the abstract class. The introduction of facade separates this subsystem from customers and other subsystems, which can improve the independence and portability of subsystems. 3. When you need to build a hierarchical subsystem, use the facade pattern to define the entry points for each layer in the subsystem, and if the subsystems are interdependent, you can make them communicate only through facade, simplifying their dependencies. Facade mode has the following advantages: 1, it to the customer shielding subsystem components, thus reducing the number of objects processed by customers and make the subsystem more convenient to use. 2, it realizes the loose coupling between the subsystem and the customer, and the functional components inside the subsystem are often tightly coupled. Loosely coupled relationships make the components of a subsystem change without affecting its customers. The facade pattern helps to build a hierarchical system and also helps to layer dependencies between objects. The facade pattern eliminates complex cyclic dependencies. This is especially important when the client program and subsystem are implemented separately. Reducing compilation dependencies in large software systems is critical. When the subsystem class changes, you want to minimize the recompilation effort to save time. Using facade can reduce compilation dependencies and limit the recompilation required for minor changes in important systems. The facade model also facilitates the simplification of the porting process between different platforms, since compiling a subsystem generally does not require compiling all of the other subsystems. 3. If the application requires it, it does not restrict their use of subsystem classes. So you can choose between system ease of use and versatility.
Package App.fcade;public class Fcade1 {public static void main (string[] args) {facade fa=new facade (); Fa.chuang ();}} Class Facade{pass1 P1=new Pass1 ();p ass2 p2=new pass2 ();p ublic void Chuang () {p1.getpass ();p 2.getPass ();}} Class Pass1{public void Getpass () {System.out.println ("first pass"); Intonext ();} public void Intonext () {System.out.println ("Go to Next Pass");}} Class Pass2{public void Getpass () {System.out.println ("go through the second Pass"); Intonext (); public void Intonext () {System.out.println ("Go to Next Pass");}}
The appearance pattern is to encapsulate the inner class consent into a class, provide an interface for external use, do not need to face scattered classes for a series of tedious operations
Java demo facade (appearance) mode