Design pattern appearance (facade) mode (note)

Source: Internet
Author: User

The appearance mode (facade) provides a consistent interface for a set of interfaces in a subsystem that defines a high-level interface that makes this subsystem easier to use.
The appearance pattern perfectly embodies the thought that relies on the reversal principle and the Dimitri rule, so it is one of the more common design patterns.
The appearance mode structure diagram is as follows:

Define three subsystem classes

 Public classSubsystemone { Public void MethodOne() {System. out. println ("Subsystem Method 1"); }} Public classSubsystemtwo { Public void Methodtwo() {System. out. println ("Subsystem Method 2"); }} Public classSubsystemthree { Public void Methodthree() {System. out. println ("Subsystem Method 3"); }}

Define a skin facade class

public      Class  facade {private  subsystemone one; private     Subsystemtwo; private     Subsystemthree three; public  facade         () {One =new  subsystemone ();        Two=new  subsystemtwo ();    Three=new  subsystemthree (); } public  void          MethodA  () {one.methodone ();    Three.methodthree (); } public  void          MethodB  () {one.methodone ();    Two.methodtwo (); }}

Client code

publicstaticvoidmain(String[] args) {        Facade facade=new Facade();        facade.methodA();        facade.methodB();}

Due to the role of the facade class, the client can not know the existence of three subsystems at all

Design pattern appearance (facade) mode (note)

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.