CoursesGalaxy Courses Subscription Knowledge Hub
Knowledge Hub
Design Patterns
    Creational Patterns
    Structural Patterns
        Adapter
        Bridge
        Composite
        Decorator
        Facade
        Flyweight
        Proxy
    Behavioral Patterns


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 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 it 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.
Structure

Facade Design Pattern

Participant classes
  • 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.
Example

Implementation Code

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



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 is from his courses on design patterns.







Yearly Subscription


Design Patterns in C++


Advanced Python

Explore

Courses

Subscription

Knowledge Hub

Design Patterns

Tech Articles

About Us

Overview

Contact Us

CourseGalaxy

CourseGalaxy is focused on transformation of Engineering graduate to Software Engineer to fill the gap between education and industry and provide the training on specific problems of industry to enhance the skills of Engineers in industry to do their job appropriately.

Learn From Us

2018 CourseGalaxy