1.基本概念

2.代码
package com.chengjie; class SystemLight { public void on() { System.out.println("灯打开了!"); } public void off() { System.out.println("灯关闭了!"); } } class SystemTelevision { public void on() { System.out.println("电视打开了!"); } public void off() { System.out.println("电视关闭了!"); } } class SystemAircontion { public void on() { System.out.println("空调打开了!"); } public void off() { System.out.println("空调关闭了!"); } } class Facade { SystemLight sl; SystemTelevision st; SystemAircontion sa; public Facade(SystemLight sl, SystemTelevision st, SystemAircontion sa) { this.sl = sl; this.st = st; this.sa = sa; } public void on() { System.out.println("起床了!"); this.sl.on(); this.st.on(); this.sa.on(); } public void off() { System.out.println("睡觉了!"); this.sl.off(); this.st.off(); this.sa.off(); } } public class TestFacadePattern { public static void main(String[] args) { Facade f = new Facade(new SystemLight(), new SystemTelevision(), new SystemAircontion()); f.on(); f.off(); } }
3.优点
4.缺点
5.应用场景
6.参考
https://www.jianshu.com/p/1b027d9fc005
原文:https://www.cnblogs.com/forTheDream1991/p/10457505.html