> Design Patterns > Facade Design Pattern

Facade Design Pattern

Facade design pattern is used to provide simple interface to use an existing system in an easy way.

Intent

  • Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.

The intent of facade design pattern is to provide unified interface for a set of interfaces of subsystem to make it easy to use.

Problem

  • It is difficult for client to use the subsystem with existing interfaces.
Facade Design Pattern Problem

The client has to use multiple interfaces of different subsystem classes to use the existing subsystem. This makes using the subsystem complex as the number of interfaces grow.

Solution

  • Come up with a new simplified interface for client to use the system easily.
Facade Design Pattern Solution

The new simplified interface will use the existing subsystem interfaces. It will be easy for client to use the new interface instead of using the multiple subsystem interfaces and going into detail of knowing the existing subsystem working and how the whole things are related.

Where facade design pattern is applicable?

  • There are lot of subsystem classes and it is complex to use the subsystem as there is lot of dependency within them. So simple interface for client makes it easy to use.

Facade Design Pattern UML Structure

Facade Design Pattern UML Structure

Participant classes of facade design pattern

  • Classes SybsystemClass1, SubsystemClass2 and SubsystemClass3 represent the existing complex subsystem which provides functionality by using multiple interfaces.
  • FacadeSystem class provides new simple interface to client.

How they work together?

  • FacadeSystem has instances of classes SubsystemClass1, SubsystemClass2 and SubsystemClass3. It uses their methods to provide the functionality. Client uses the new provided interface Method1 and Method2 of FacadeSystem. The client need not know the details of existing complex system as it is taken care of by FacadeSystem.
  • the client just uses the interfaces provided by FacadeSystem and FacadeSystem uses the appropriate subsystem interfaces in a way required for a functionality. If required, subsystem can be used independently too.

Facade Design Pattern Example

Here is the facade design pattern example.

There are components lexical analyzer, parser, code generator, archiver. A tool is required to compile, build, create library. It will be difficult to use them for user, so provide simple interface in tool for user.

Implementation Code

C++ Facade Pattern in C++ Facade Pattern C++ Example
C# Facade Pattern in C# Facade Pattern C# Example
Java Facade Pattern in Java Facade Pattern Java Example
Python Facade Pattern in Python Facade Pattern Python Example
JavaScript Facade Pattern in JavaScript Facade Pattern JavaScript Example
PHP Facade Pattern in PHP Facade Pattern PHP Example
Ruby Facade Pattern in Ruby Facade Pattern Ruby Example
Swift Facade Pattern in Swift Facade Pattern Swift Example
Objective-C Facade Pattern in Objective-C Facade Pattern Objective-C Example


Suresh Kumar Srivastava is founder of online learning site coursegalaxy.com and author of popular books C In Depth, Data Structures Through C In Depth. He has 18+ years experience in industry and worked on architecture and design of multiple products. This article Facade Design Pattern is from his Design Patterns course.