《吸血鬼倖存者》女巫奶牛場打法分享
阿新 • • 發佈:2022-04-19
package com.life.design.facade; public class SmartAppliancesFacade { private Light light; private TV tv; private AirCondition airCondition; public SmartAppliancesFacade() { light = new Light(); tv = new TV(); airCondition = new AirCondition(); } publicvoid say(String message) { if (message.contains("開啟")) { on(); } else if (message.contains("關閉")) { off(); } else { System.out.println("我還聽不懂你說的"); } } public void on() { light.on(); tv.on(); airCondition.on(); }public void off() { light.off(); tv.off(); airCondition.off(); } }
package com.life.design.facade; public class Light { public void on() { System.out.println("開啟電燈"); } public void off() { System.out.println("關閉電燈"); } }
package com.life.design.facade;public class Client { public static void main(String[] args) { SmartAppliancesFacade facade = new SmartAppliancesFacade(); facade.say("開啟"); facade.say("關閉"); } }