package com.jmj.pattern.facade;public class Light {public void on(){System.out.println("打开电灯...");}public void off(){System.out.println("关闭电灯...");}
}
package com.jmj.pattern.facade;public class AirCondition {public void on(){System.out.println("打开空调...");}public void off(){System.out.println("关闭空调...");}}
package com.jmj.pattern.facade;public class TV {public void on(){System.out.println("打开电视机...");}public void off(){System.out.println("关闭电视机...");}}
package com.jmj.pattern.facade;public class SmartAppliancesFacade {private AirCondition airCondition;private Light light;private TV tv;public SmartAppliancesFacade() {light=new Light();tv=new TV();airCondition=new AirCondition();}public void say(String message){if (message.equals("打开")){on();} else if (message.equals("关闭")) {off();}else {System.out.println("我听不懂你说的!!!");}}private void on() {light.on();airCondition.on();tv.on();}private void off() {light.off();airCondition.off();tv.off();}
}
package com.jmj.pattern.facade;public class Client{public static void main(String[] args) {SmartAppliancesFacade smartAppliancesFacade = new SmartAppliancesFacade();smartAppliancesFacade.say("关闭");}
}