Facade pattern hides the complexities of the system and provide the interface to use that system.
Here we are going to create a shape interface that will be provided to client for using the Shape Maker.
Step-1 Create an interface Shape
interface Shape { public void draw(); } class Circle implements Shape { public void draw() { system.out.println("Hi, this is circle"); } } class Rectangle implements Shape { public void draw() { system.out.println("Hi, this is rectangle"); } } class Square implements Shape { public void draw() { system.out.println("Hi, this is square"); } } class ShapeMaker { Shape circle; Shape rectangle; Shape square; ShapeMaker(Shape shape) { 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 FacadeDemo { ShapeMaker shapeMaker = new ShapeMaker(); public static void main(String[] arg) { shapeMaker.drawCircle(); shapeMaker.drawRectangle(); shapeMaker.drawSquare(); } }
Output:
Hi, this is circle
Hi, this is rectangle
Hi, this is square