Design Patterns - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Façade Pattern

Façade Pattern

shape Description

Facade pattern is one type of structural pattern, which hides the complexity of the system and provides an interface for clients to access the system. Every abstract factory is a facade pattern by default. Client can easily interact with the system applications.

shape Advantages

  • Complexity is hidden.
  • Sub systems can be easily accessed.
  • Allows loose coupling.

shape Conceptual figure

shape Examples

Creating an interface Design. [java] public interface Design { void draw(); }[/java] Creating a class Triangle which implements the interface Design. [java] public class Triangle implements Design { public void draw() { System.out.println("Triangle::draw()"); } }[/java] Creating a class Rhombus and implementing the interface Design. [java] public class Rhombus implements Design { public void draw() { System.out.println("Rhombus::draw()"); } }[/java] Creating a class Circle which implements the interface Design. [java] public class Circle implements Design { public void draw() { System.out.println("Circle::draw()"); } }[/java] Creating a Facade class DesignMaker. [java] public class DesignMaker { private Design circle; private Design triangle; private Design Rhombus; public DesignMaker() { circle = new Circle(); triangle = new Triangle(); rhombus = new Rhombus(); } public void drawCircle() { circle.draw(); } public void drawTriangle() { rectangle.draw(); } public void drawRhombus() { square.draw(); } }[/java] Creating a main class FacadePattern. [java] public class FacadePattern { public static void main(String[] args) { DesignMaker designMaker = new DesignMaker(); designMaker.drawCircle(); designMaker.drawTriangle(); designMaker.drawRhombus(); } }[/java]

shape Output

Result will be as follows. [java] Circle::draw() Triangle::draw() Rhombus::draw()[/java]

Summary

shape Key Points

  • Façade Pattern - Complexity is reduced.
  • Façade Pattern - Interface is designed to provide access to the client.
  • Facade objects are singletons.