Skip to content
APPCITORThe Tech Blog
Esc

Structural – Facade Design Pattern

July 30, 2020 1 min read

Structural – Facade Design Pattern

Facade Design Pattern is categorized under Structural Design Patterns. A facade is an object that provides a simplified interface to a larger body of code. We can use facade design pattern to make a software library easier to use, understand and test. Also make the library more readable.

Let’s start to discuss about the facade design pattern by using an example.

I will take about different kind of swimmers as the example. You know that all kind of swimmers do swim. So as the first step I will make an interface called “Swimmer” and write the method “swim()” inside the interface. And then I will make 2 classes for 2 kinds of swimmers called “DistanceSwimmer” and “Sprinter” by implementing the interface.

Here I made another 2 methods that is ideal for each class. You can see the complexity of this internal system for an end user is high. So let’s make a facade class to reduce the complexity of the system.

Here you can see I made 2 objects for the 2 classes “DistanceSwimmer” and “Sprinter” and using the references of the objects I called the 4 methods created inside those 2 classes by creating new methods called “Sprint()” and “DistanceSwim()”. Let’s create the main method.

You know that I don’t want to create 2 objects on the 2 classes “DistanceSwimmer” and “Sprint” because already I made them in another class called “WaterSport”. Therefore I need only to create the object of that class and call the methods that I created inside the class. See the end user will not even know that there are 2 more classes were created in the system. Output will be as given below.

If you want to learn about creational design patterns, go to the links i mentioned below.

Thank you.

Creational Design Patterns

Singleton Design Pattern

Factory Design Pattern

Abstract Factory Design Pattern

Prototype Design Pattern

Builder Design Pattern

Share this article

Keep reading