设计模式之外观(facade)
程序员文章站
2022-05-17 19:36:37
...
public class Facade { class Engine{ public void run(){ System.out.println("engine is run..."); } public void stop(){ System.out.println("engine is stop..."); } } class Wheel{ public void run(){ System.out.println("wheel is run..."); } public void stop(){ System.out.println("wheel is stop..."); } } //向外提供一个接口 class CarFacade{ Engine engine = new Engine(); Wheel wheel = new Wheel(); public void carRun(){ engine.run(); wheel.run(); } public void carStop(){ engine.stop(); engine.run(); } } public static void main(String[] args) { Facade facade = new Facade(); CarFacade car = facade.new CarFacade(); car.carRun(); car.carStop(); } }
上一篇: 设计模式之模板模式
下一篇: lucene--搜索工具类