当前位置: 代码迷 >> 综合 >> java外观模式-Facade
  详细解决方案

java外观模式-Facade

热度:50   发布时间:2023-12-12 17:10:08.0

类图

外观类代码

public class ShapeMaker {private Shape circle;private Shape rectangle;private Shape square;public ShapeMaker() {circle = new Circle();rectangle = new Rectangle();square = new Square();}public void drawCircle(){circle.draw();}public void drawRectangle(){rectangle.draw();}public void drawSquare(){square.draw();}
}

使用外观类

public class FacadePatternDemo {public static void main(String[] args) {ShapeMaker shapeMaker = new ShapeMaker();shapeMaker.drawCircle();shapeMaker.drawRectangle();shapeMaker.drawSquare();      }
}
  相关解决方案