Appearance mode of Java design pattern

Source: Internet
Author: User

Appearance pattern Concept

Appearance mode, also known as façade mode, provides a consistent interface for a set of interfaces in a subsystem that defines a hierarchical interface that makes this subsystem easier to use. This pattern perfectly embodies the idea of relying on the reversal principle and the Dimitri rule, so it is one of the most common patterns.

Appearance mode UML diagram

  

Appearance Pattern Code

Learning the appearance pattern I used an example of a fight, fights generally do not want to be seen, as long as the people know to hit the can.

 PackageCom.roc.face;/*** Façade mode interface fight can't be seen by others@authorLIAOWP **/ Public InterfaceFaceinterface {/*** Who to fight with *@paramname*/     Public voidFight (String name); /*** Give sugar *@paramNum*/     Public voidGivetang (intnum);}
 PackageCom.roc.face;/*** Specific Implementation method *@authorLIAOWP **/ Public classFaceimlImplementsfaceinterface{/*** Fight*/     Public voidFight (String name) {System.out.println ("Hit" +name); }        /*** Give sugar *@paramNum*/     Public voidGivetang (intnum) {System.out.println ("Can't get revenge, give You" +num+ "Candy"); }        }
 Package Com.roc.face; /**  @author*/Publicclass  facemodel    {  Private faceinterface  faceinterface=new  faceiml ();          Public void Deal (String name,int  num) {        faceinterface.fight (name);        Faceinterface.givetang (num);    }}
 PackageCom.roc.face;/*** Use scene *@authorLIAOWP **/ Public classClient { Public Static voidMain (string[] args) {Facemodel Facemodel=NewFacemodel (); String name= "LIAOWP"; Facemodel.deal (Name,1);//Do not care how to fight inside, only know to hit that person. This is the façade if now after the fight fear revenge, and gave a piece of sugar, just need to modify the interface over there on it.     }}
Appearance mode applicable scenario (1) The initial stage of the design should be conscious of separating the different layers and establishing the appearance pattern between the layers and the layers. (2) During the development stage, the subsystem becomes more and more complex, and the appearance mode is added to provide a simple calling interface. (3) When maintaining a large legacy system, it is possible that the system is very difficult to maintain and extend, but it also contains very important features for it to develop an appearance class so that the new system interacts with it.

Appearance mode of Java design pattern

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.