Structural Design Pattern: Facade Pattern - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Random Posts

Structural Design Pattern: Facade Pattern

Share This
The Facade Pattern is a design principle that advocates for the provision of a single, streamlined interface to a collection of interfaces within a subsystem. This approach effectively conceals the intricacies of the subsystem from the client.

The Facade Pattern can be defined as an abstraction layer that provides a simplified interface for a complex subsystem.

Essentially, every Abstract Factory can be considered a subtype of Facade.
 
It protects the clients from the intricacies of the sub-system components. It facilitates a low level of dependency between subsystems and the entities that use them.
 
Application of the Facade Pattern:
  • When you desire to offer a straightforward interface for an intricate sub-system. 
  • When there are several dependencies between clients and the implementation classes of an abstraction.

Source code of ShapeFacade.java
package com.t4b.test.java.dp.sp.fp; class ShapeFacade { interface Shape { void draw(); } class Rectangle implements Shape { @Override public void draw() { System.out.println("Drawing Rectangle!"); } } class Square implements Shape { @Override public void draw() { System.out.println("Drawing Square!"); } } class Circle implements Shape { @Override public void draw() { System.out.println("Drawing Circle!"); } } private Shape circle = new Circle(); private Shape rectangle = new Rectangle(); private Shape square = new Square(); public ShapeFacade() { } public void drawCircle() { circle.draw(); } public void drawRectangle() { rectangle.draw(); } public void drawSquare() { square.draw(); } }
Source code of TestMain.java
package com.t4b.test.java.dp.sp.fp; public class TestMain { public static void main(String[] args) { ShapeFacade shapeFacade = new ShapeFacade(); shapeFacade.drawCircle(); shapeFacade.drawRectangle(); shapeFacade.drawSquare(); } }

Happy Exploring!

No comments:

Post a Comment