Facade Pattern

A Facade Pattern says that just "just provide a unified and simplified interface to a set of interfaces in a subsystem, therefore it hides the complexities of the subsystem from the client".

In other words, Facade Pattern describes a higher-level interface that makes the sub-system easier to use.

Practically, every Abstract Factory is a type of Facade.


Advantage of Facade Pattern

  • It shields the clients from the complexities of the sub-system components.
  • It promotes loose coupling between subsystems and its clients.

Usage of Facade Pattern:

It is used:

  • When you want to provide simple interface to a complex sub-system.
  • When several dependencies exist between clients and the implementation classes of an abstraction.

Example of Facade Pattern

Let's understand the example of facade design pattern by the above UML diagram.

UML for Facade Pattern:

Facade Pattern UML

Implementation of above UML:

Step 1

Create a MobileShop interface.

File: MobileShop.java

Step 2

Create a Iphone implementation class that will implement Mobileshop interface.

File: Iphone.java

Step 3

Create a Samsung implementation class that will implement Mobileshop interface.

File: Samsung.java

Step 4

Create a Blackberry implementation class that will implement Mobileshop interface .

File: Blackberry.java

Step 5

Create a ShopKeeper concrete class that will use MobileShop interface.

File: ShopKeeper.java

Step 6

Now, Creating a client that can purchase the mobiles from MobileShop through ShopKeeper.

File: FacadePatternClient.java

Output





Latest Courses