23 Design Modes (21): Appearance mode

Source: Internet
Author: User


Providing a consistent interface for a set of interfaces in a subsystem, the facade schema defines a high-level interface that makes this subsystem easier to use.

Type: Structural mode.

Class Diagram:

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 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.

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 large dependency 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.

If subsystems are interdependent, you can make them communicate only through facade, simplifying their dependencies.



Know which subsystem classes are responsible for processing requests.

The client's request is proxied to the appropriate subsystem object.


Implement the functions of the subsystem.

Handles tasks assigned by the facade object.

There is no relevant information for facade; that is, there is no pointer to facade.


FaçadePublicClassfacade {ServiceA sa;    SERVICEB SB; SERVICEC SC;PublicFacade () {sa =New Serviceaimpl (); SB =New Servicebimpl (); sc =New Servicecimpl (); }PublicvoidMethodA () {Sa.methoda (); Sb.methodb ();}PublicvoidMethodB () {sb.methodb (); Sc.methodc ();}PublicvoidMethodc () {sc.methodc (); Sa.methoda ();}} SubsystemclassesPublicClassServiceaimplImplementsServiceA {PublicvoidMethodA () {System.out.println ("This is Service a"); }}PublicClassServicebimplImplementsSERVICEB {PublicvoidMethodB () {System.out.println ("This is Service B"); }}PublicClassServicecimplimplements SERVICEC {public void methodc () {System.out.println (public class test {public static  void main (string[] args) {servicea sa = new Serviceaimpl (); SERVICEB sb = new Servicebimpl (); Sa.methoda (); Sb.methodb (); System.out.println ( "========"); //facade facade facade = new facade (); Facade.methodA (); Facade.methodb (); }} 



23 Design Modes (21): Appearance mode

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.