Preliminary Research on Design Mode-appearance Mode

Source: Internet
Author: User

The appearance mode (FACADE), also called the FACADE mode, belongs to the object structure mode. It simplifies the interaction between the client and the subsystem by providing a consistent interface (appearance object) for a group of interfaces in the subsystem. The Facade mode defines a high-level interface, which provides a single and simple interface for more common sub-system facilities, so as to minimize the communication and dependency between sub-systems, in addition, the customer class and sub-system class are isolated, reducing the coupling between the two. As shown in:


I. Application scenarios

1. When you want to provide a simple portal for accessing a series of complex subsystems. The facade class effectively shields more and more sub-classes produced by the evolution of subsystems and reduces the complexity of the Access Subsystem.
2. There is a large dependency between the client program and multiple subsystems. The introduction of appearance class can decouple subsystems from clients to improve the independence and portability of subsystems.

3. When you need to build a layered sub-system, use the facade mode to define the entry points for each layer of the sub-system. If subsystems are mutually dependent, you can allow them to communicate only through facade to simplify the dependency between subsystems.

Ii. UML diagram


Iii. Java implementation

Package study. patterns. facade;/*** appearance mode is a very frequently used structural design mode. It introduces an appearance role to simplify the interaction between the client and the subsystem, * provides a unified portal for complex subsystem calls, reduces the coupling between subsystems and clients, and facilitates client calls. * Life is full of various appearance roles, such as waiters and ATMs. Because of the existence of these appearance roles, life is better! * @ Author qbg */public class FacadePattern {public static void main (String [] args) {IFacade facade = new Facade (); facade. method () ;}}/*** unified appearance interface. You can implement the corresponding appearance class as needed. * interface-Oriented Programming. */Interface IFacade {public void method ();}/*** appearance role: external appearance class implementation, which can be called on the client, it knows the functions and responsibilities of the relevant (one or more) subsystems. * normally, it delegates all requests sent from the client to the corresponding subsystems, it is passed to the corresponding subsystem object processing. */Class Facade implements IFacade {private sub‑ema sa = new sub‑ema (); private SubSystemB sb = new SubSystemB (); private sub‑emc SC = new sub‑emc (); @ Overridepublic void method () {sa. methodA (); sb. methodB (); SC. methodC () ;}/ *** subsystem role: You can have one or more subsystem roles in the software system. Each subsystem may not be a separate class, instead, it is a collection of classes that implement sub-system functions. * each sub-system can be called directly by the client or by the appearance role, which processes requests transmitted from the appearance class; * The subsystem does not know the appearance. For the subsystem, the appearance role is just another client. */Class sub‑ema {public void methodA () {System. out. println ("subsystem A business processing .... ") ;}} class SubSystemB {public void methodB () {System. out. println ("subsystem B business processing .... ") ;}} class SubSystemC {public void methodC () {System. out. println ("subsystem C business processing .... ");}}

Iv. Advantages and Disadvantages

Advantages:

1. It shields sub-system components from the client, reduces the number of objects processed by the customer, and makes the sub-system more convenient to use.
2. It implements loose coupling between the subsystem and the client, so that the subsystem changes will not affect the client that calls it. You only need to adjust the appearance class.
3. Modifications to a sub-system have no impact on other sub-systems, and internal changes in the sub-system do not affect the appearance objects.

4. The Facade mode helps to establish a hierarchical system and layer dependencies between objects.

5. The Facade mode does not limit the use of sub-system classes. You can choose between ease of use and versatility of the system as needed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.