先定义两个模块 Module1 Module2
public class Module1 { public void on() { System.out.println("media1 is on"); } public void off() { System.out.println("media1 is off"); } } public class Module2 { public void on() { System.out.println("media2 is on"); } public void off() { System.out.println("media2 is off"); } }Maker 封装之后,对外提供统一的接口
public class Maker { private Module1 module1; private Module2 module2; public Maker() { this.module1 = new Module1(); this.module2 = new Module2(); } public void on(){ module1.on(); module2.on(); } public void off(){ module1.off(); module2.off(); } }