Chirp, chirp, mulan knit. Not hearing the sound of the loom, but hearing the sigh of the woman.



Basic UML for appearance patterns:


A UML diagram of Mulan making her suit:


code

public class FineHorse {

    public void eastMarketGet(a) {
        System.out.println("East city buy horse ~");
    }
}  public class Saddle {   public void westernMarketGet(a) {  System.out.println("Buy saddles in the West.");  } }  public class BridleHead {   public void southMarketGet(a) {  System.out.println("Nanshi Buy bridle ~");  } }  public class Whip {   public void northMarketGet(a) {  System.out.println("Buy a whip in North City ~");  }  }  public class WeaponMaster {   private BridleHead bridleHead = new BridleHead();  private FineHorse fineHorse = new FineHorse();  private Saddle saddle = new Saddle();  private Whip whip = new Whip();   public void makeWararmor(a) {   fineHorse.eastMarketGet();  saddle.westernMarketGet();  bridleHead.southMarketGet();  whip.northMarketGet();   System.out.println("Equipment obtained successfully ~");  System.out.println("Congratulations, we've assembled the suit!");  }   public void give(String name) {  System.out.println("Send the robe to :" + name);  System.out.println(name + "Get the suit.");  } }  public class HuaMuLan {   public static void main(String[] args) {   WeaponMaster weaponMaster = new WeaponMaster();  weaponMaster.makeWararmor();  weaponMaster.give("Mulan");   } } Copy the code

The appearance model

Growing functions of a system, subsystem (a module) is more and more, so the client if turn to call subsystem becomes complicated, also need the subsystem has a deeper understanding, if the function is changed, the client also needs to change, in violation of the principle of opening and closing as well as the law of Demeter, so we can provide a common external interface subsystem. Clients can communicate directly with this facade object.

The practical application

Detailed you can go to see the source code

jdk : java.lang.Class

spring :org.springframework.jdbc.support.JdbcUtils

tomcat : org.apache.catalina.connector.Request

mybatis : org.apache.ibatis.session.Configuration

Mulan got the suit, said goodbye to the parents on the road, camp Yellow River, can not hear parents call daughter’s voice, but can hear the sound of the Yellow River surging.

A few years later, Mulan came back victorious as a heroine.

The article continues to be updated at ⛽️. Additional blogger arranges + original 150 thousand literal test questions, including 17 special topics. Follow “Java Junior talent show” reply to “Interview” to obtain the Java junior talent show interview notes. PDF

This article is formatted using MDNICE