
package com.eric.结构型模式.门面模式.引例;
import javax.xml.transform.Source;
/**
 * @author Eric
 * @ProjectName my_design_23
 * @description 子系统
 * @CreateTime 2020-12-02 18:04:23
 */
public class ClassA {
    public void methodA(){
        System.out.println("A的方法A");
    }
}
class ClassB {
    public void methodB(){
        System.out.println("B的方法B");
    }
}
class ClassC {
    public void methodC(){
        System.out.println("C的方法C");
    }
}package com.eric.结构型模式.门面模式.引例;
import com.sun.org.apache.bcel.internal.generic.NEW;
/**
 * @author Eric
 * @ProjectName my_design_23
 * @description 外观角色
 * @CreateTime 2020-12-02 18:29:36
 */
public class Facade {
    //被委托的对象
    private ClassA a = new ClassA();
    private ClassB b = new ClassB();
    private ClassC c = new ClassC();
    //提供外界的方法
    public void methodA(){
        a.methodA();
    }
    public void methodB(){
        b.methodB();
    }
    public void methodC(){
        c.methodC();
    }
}package com.eric.结构型模式.门面模式.例1;
/**
 * @author Eric
 * @ProjectName my_design_23
 * @description 机场类
 * @CreateTime 2020-12-02 18:53:22
 */
public class Airport {
    public void bookTicket(String from,String to){
        System.out.println("订购了从"+from+"到"+to+"的机票");
    }
}package com.eric.结构型模式.门面模式.例1;
/**
 * @author Eric
 * @ProjectName my_design_23
 * @description 宾馆类
 * @CreateTime 2020-12-02 18:56:21
 */
public class Hotel {
    public void reserve(int days){
        System.out.println("预定了"+days+"天的双人间");
    }
}package com.eric.结构型模式.门面模式.例1;
/**
 * @author Eric
 * @ProjectName my_design_23
 * @description 酒店类
 * @CreateTime 2020-12-02 18:55:02
 */
public class Restaurant {
    public void reserve(int num){
        System.out.println("定了一桌"+num+"人的酒席。");
    }
}package com.eric.结构型模式.门面模式.例1;
/**
 * @author Eric
 * @ProjectName my_design_23
 * @description 司机类
 * @CreateTime 2020-12-02 18:57:41
 */
public class Chauffeur {
    public void drive(String to){
        System.out.println("司机开车到"+to);
    }
}package com.eric.结构型模式.门面模式.例1;
/**
 * @author Eric
 * @ProjectName my_design_23
 * @description 秘书类
 * @CreateTime 2020-12-02 18:58:34
 */
public class Secretary {
    private Chauffeur chauffeur = new Chauffeur();
    private Hotel hotel = new Hotel();
    private Restaurant restaurant = new Restaurant();
    private Airport airport = new Airport();
    //安排出差
    public void trip(String to,int days){
        airport.bookTicket("青岛",to);
        chauffeur.drive("机场");
        hotel.reserve(days);
    }
    //安排饭局
    public void repast(int num){
        restaurant.reserve(num);
        chauffeur.drive("酒店");
    }
}package com.eric.结构型模式.门面模式.例1;
import jdk.management.resource.internal.inst.SocketOutputStreamRMHooks;
/**
 * @author Eric
 * @ProjectName my_design_23
 * @description 老板使用秘书
 * @CreateTime 2020-12-02 19:13:29
 */
public class Boss {
    public static void main(String[] args) {
        Secretary secretary = new Secretary();
        System.out.println("老板告诉秘书要到上海出差10天...");
        secretary.trip("上海",10);
        System.out.println("-------------------------------");
        System.out.println("老板告诉秘书要请8个人吃饭...");
        secretary.repast(8);
    }
}
原文:https://www.cnblogs.com/zyl-0110/p/14204689.html