Java design pattern--structural mode--appearance mode

Source: Internet
Author: User

1 appearance mode2 Overview3 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. 4  5  6 Applicability71. When you want to provide a simple interface for a complex subsystem. Subsystems tend to become more and more due to evolving8 Complex. Most patterns will produce more and smaller classes when used. This makes the subsystem more reusable and more9 easy to customize for sub-systems, but this also brings some difficulties to users who do not need to customize the subsystem. Ten facade can provide a simple default view that is sufficient for most users, and those that need One For more customizable users can cross the facade layer.  A  -2there is a large dependency between the client program and the implementation part of the abstract class. Introduce facade this subsystem with the customer - And other subsystems can improve the independence and portability of subsystems.  the  -3when 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 - the dependencies between them.  +   -   + participants A1. Facade at know which subsystem classes are responsible for processing requests.  - The client's request is proxied to the appropriate subsystem object.  -  -2. Subsystemclasses - implement the functions of the subsystem.  - handles tasks assigned by the facade object.  inThere is no relevant information for facade; that is, there is no pointer to facade.

Test class:

1  Public classTest {2     3      Public Static voidMain (string[] args) {4ServiceA SA =NewServiceaimpl ();5SERVICEB SB =NewServicebimpl ();6         7 Sa.methoda ();8 Sb.methodb ();9         TenSystem.out.println ("========"); One         //facade AFacade facade =Newfacade (); - Facade.methoda (); - Facade.methodb (); the     } -}
1  Public Interface ServiceA {2      Public void MethodA (); 3 }
 1  public  class  Serviceaimpl implements   ServiceA { 2  public  void   MethodA () { 4  SYSTEM.OUT.PR Intln ("This is Service a"  5   6  }
 1  public  interface       ServiceB { 2  public  void   MethodB ();  3 } 
 1  public  class  Servicebimpl implements   ServiceB { 2  public  void   MethodB () { 4  SYSTEM.OUT.PR Intln ("This is Service B"  5   6  }
 1  public  interface       SERVICEC { 2  public  void   METHODC ();  3 } 
1  Public class Implements SERVICEC {23      Public void methodc () {4         System.out.println ("This is Service C"); 5     }6 }
1  Public classFacade {2 3 ServiceA sa;4     5 SERVICEB sb;6     7 SERVICEC SC;8     9      Publicfacade () {TenSA =NewServiceaimpl (); OneSB =NewServicebimpl (); Asc =NewServicecimpl (); -     } -      the      Public voidMethodA () { - Sa.methoda (); - Sb.methodb (); -     } +      -      Public voidMethodB () { + Sb.methodb (); A sc.methodc (); at     } -      -      Public voidmethodc () { - sc.methodc (); - Sa.methoda (); -     } in}

Java design pattern--structural mode--appearance mode

Related Article

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.