Dictionary meaning of façade: The principal front of a building, that faces on to a street or open space.
Java façade design pattern comes under structural design patterns and it is used to hide the complexity of the system by providing a unified and simplified interface to a set of interfaces in a subsystem.
Main advantage of façade design pattern is that it provides loose coupling between client and subsystems.
Example
Shape.java
package com.w3schools; public interface Shape { public void createShape(); } |
Rectangle.java
package com.w3schools; public class Rectangle implements Shape { @Override public void createShape() { System.out.println("Rectangle created."); } } |
Circle.java
package com.w3schools; public class Circle implements Shape { @Override public void createShape() { System.out.println("Circle created."); } } |
ShapeFactory.java
package com.w3schools; public class ShapeFactory { private Shape circle; private Shape rectangle; public ShapeFactory() { circle = new Circle(); rectangle = new Rectangle(); } public void createCircle(){ circle.createShape(); } public void createRectangle(){ rectangle.createShape(); } } |
FacadePatternTest.java
package com.w3schools; public class FacadePatternTest { public static void main(String args[]){ ShapeFactory shapeFactory = new ShapeFactory(); shapeFactory.createCircle(); shapeFactory.createRectangle(); } } |
Output
Circle created.
Rectangle created. |