Shape接口
public interface Shape { public void draw(); }接口实现
public class Square implements Shape{ @Override public void draw() { System.out.println("Square::draw()"); } }接口实现
public class Rectangle implements Shape{ @Override public void draw() { System.out.println("Rectangle::draw()"); } }接口实现
public class Circle implements Shape{ @Override public void draw() { System.out.println("Circle::draw()"); } }Shape外观类
/** * @author wxy * @description Shape外观类 * @data 2020/7/2 */ 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(); } }