Facade Design Pattern (original) (raw)

Last Updated : 6 May, 2026

The Facade Design Pattern is a structural pattern that provides a simple and unified interface to a complex subsystem. It hides the internal complexity of the system, making it easier to use and maintain.

**Example: In a home automation system, a user controls lights, AC, and security cameras using a single app or panel. The control system acts as a Facade, hiding the complexity of multiple devices. It provides one simple interface to manage all subsystems efficiently.

Fcade

Facade Design Pattern

In the above diagram:

**Note: Facade Method Design Pattern provides a unified interface to a set of interfaces in a subsystem. Facade defines a high-level interface that makes the subsystem easier to use.

Real Life applications

The Facade Pattern is commonly used to provide a simplified interface to complex subsystems in real-world applications.

Components

The Facade Pattern consists of key components that help simplify interactions with complex systems.

component_of_facade_method_design_pattern

Consider for example a programming environment that gives applications access to its compiler subsystem.

1. Facade (Compiler)

Provides a simplified interface to interact with the complex compiler subsystem.

2. Subsystem classes (Scanner, Parser, ProgramNode, etc.)

These classes perform the core functionality of the compiler system.

3. Interface

Defines the set of high-level operations that the client can use.

Working

The facade acts as a single entry point that coordinates and delegates requests to multiple subsystem classes.

Uses

The Facade Pattern is used to provide a simplified and unified interface to complex subsystems, making them easier for clients to use.

Implementation Example

Problem Statement:

Consider a hotel where multiple restaurants serve different types of food such as veg, non-veg, and mixed options. As a customer, you don’t interact with each restaurant directly or know their menus. Instead, you communicate with the hotel keeper, who understands the system and fetches the required menu for you. This simplifies your interaction by providing a single point of access to multiple services.

file

This example shows the practical application of the design pattern using code.

1. Interface of Hotel

C++ `

package structural.facade;

public interface Hotel { public Menus getMenus(); }

Java

package structural.facade;

public interface Hotel { public Menus getMenus(); }

Python

from abc import ABC, abstractmethod

class Hotel(ABC): @abstractmethod def get_menus(self): pass

JavaScript

// JavaScript does not have interfaces, but we can simulate one using a class with abstract methods class Hotel { getMenus() { throw new Error("Method getMenus() must be implemented."); } }

`

**Note : The hotel interface only returns Menus. Similarly, the Restaurant are of three types and can implement the hotel interface. Let’s have a look at the code for one of the Restaurants.

2. NonVegRestaurant

C++ `

package structural.facade;

public class NonVegRestaurant implements Hotel {

public Menus getMenus()
{
    NonVegMenu nv = new NonVegMenu();
    return nv;
}

}

Java

package structural.facade;

public class NonVegRestaurant implements Hotel {

public Menus getMenus()
{
    NonVegMenu nv = new NonVegMenu();
    return nv;
}

}

Python

from structural.facade import Hotel, Menus, NonVegMenu

class NonVegRestaurant(Hotel):

def get_menus(self):
    nv = NonVegMenu()
    return nv

JavaScript

class NonVegRestaurant { getMenus() { let nv = new NonVegMenu(); return nv; } }

`

3. VegRestaurant

C++ `

package structural.facade;

public class VegRestaurant implements Hotel {

public Menus getMenus()
{
    VegMenu v = new VegMenu();
    return v;
}

}

Java

package structural.facade;

public class VegRestaurant implements Hotel { public Menus getMenus() { VegMenu v = new VegMenu(); return v; } }

Python

class VegRestaurant: def getMenus(self): v = VegMenu() return v

JavaScript

class VegRestaurant { getMenus() { let v = new VegMenu(); return v; } }

`

4. VegNonBothRestaurant

C++ `

package structural.facade;

public class VegNonBothRestaurant implements Hotel {

public Menus getMenus()
{
    Both b = new Both();
    return b;
}

}

Java

package structural.facade;

public class VegNonBothRestaurant implements Hotel { public Menus getMenus() { Both b = new Both(); return b; } }

Python

class VegNonBothRestaurant: def getMenus(self): b = Both() return b

JavaScript

class VegNonBothRestaurant { getMenus() { let b = new Both(); return b; } }

`

**Now consider the facade Design Pattern with the help of code:

1. HotelKeeper

C++ `

/*package whatever //do not write package name here */

#include using namespace std;

class VegMenu {}; class NonVegMenu {}; class Both {};

class HotelKeeper { public: virtual VegMenu getVegMenu() = 0; virtual NonVegMenu getNonVegMenu() = 0; virtual Both getVegNonMenu() = 0; };

Java

/*package whatever //do not write package name here */

package structural.facade;

public interface HotelKeeper {

public VegMenu getVegMenu(); public NonVegMenu getNonVegMenu(); public Both getVegNonMenu(); }

Python

"""package whatever //do not write package name here """

from abc import ABC, abstractmethod

class HotelKeeper(ABC):

@abstractmethod
def getVegMenu(self):
    pass

@abstractmethod
def getNonVegMenu(self):
    pass

@abstractmethod
def getVegNonMenu(self):
    pass

JavaScript

/*package whatever //do not write package name here */

// Assuming the existence of classes VegMenu, NonVegMenu, and Both

class HotelKeeper { getVegMenu() { throw new Error("Method not implemented."); } getNonVegMenu() { throw new Error("Method not implemented."); } getVegNonMenu() { throw new Error("Method not implemented."); } }

`

2. HotelKeeper Implementation

C++ `

package structural.facade;

public class HotelKeeperImplementation implements HotelKeeper {

public VegMenu getVegMenu()
{
    VegRestaurant v = new VegRestaurant();
    VegMenu vegMenu = (VegMenu)v.getMenus();
    return vegMenu;
}

public NonVegMenu getNonVegMenu()
{
    NonVegRestaurant v = new NonVegRestaurant();
    NonVegMenu NonvegMenu = (NonVegMenu)v.getMenus();
    return NonvegMenu;
}

public Both getVegNonMenu()
{
    VegNonBothRestaurant v = new VegNonBothRestaurant();
    Both bothMenu = (Both)v.getMenus();
    return bothMenu;
}

}

Java

package structural.facade;

public class HotelKeeperImplementation implements HotelKeeper {

public VegMenu getVegMenu()
{
    VegRestaurant v = new VegRestaurant();
    VegMenu vegMenu = (VegMenu)v.getMenus();
    return vegMenu;
}

public NonVegMenu getNonVegMenu()
{
    NonVegRestaurant v = new NonVegRestaurant();
    NonVegMenu NonvegMenu = (NonVegMenu)v.getMenus();
    return NonvegMenu;
}

public Both getVegNonMenu()
{
    VegNonBothRestaurant v = new VegNonBothRestaurant();
    Both bothMenu = (Both)v.getMenus();
    return bothMenu;
}

}

Python

from abc import ABC, abstractmethod

class HotelKeeper(ABC): @abstractmethod def getVegMenu(self): pass

@abstractmethod
def getNonVegMenu(self):
    pass

@abstractmethod
def getVegNonMenu(self):
    pass

class VegRestaurant: def getMenus(self): return VegMenu()

class NonVegRestaurant: def getMenus(self): return NonVegMenu()

class VegNonBothRestaurant: def getMenus(self): return Both()

class HotelKeeperImplementation(HotelKeeper):

def getVegMenu(self):
    v = VegRestaurant()
    vegMenu = v.getMenus()
    return vegMenu

def getNonVegMenu(self):
    v = NonVegRestaurant()
    nonVegMenu = v.getMenus()
    return nonVegMenu

def getVegNonMenu(self):
    v = VegNonBothRestaurant()
    bothMenu = v.getMenus()
    return bothMenu

class VegMenu: pass

class NonVegMenu: pass

class Both: pass

JavaScript

class HotelKeeper { getVegMenu() { throw new Error('Method not implemented.'); } getNonVegMenu() { throw new Error('Method not implemented.'); } getVegNonMenu() { throw new Error('Method not implemented.'); } }

class VegRestaurant { getMenus() { return new VegMenu(); } }

class NonVegRestaurant { getMenus() { return new NonVegMenu(); } }

class VegNonBothRestaurant { getMenus() { return new Both(); } }

class HotelKeeperImplementation extends HotelKeeper {

getVegMenu() {
    let v = new VegRestaurant();
    let vegMenu = v.getMenus();
    return vegMenu;
}

getNonVegMenu() {
    let v = new NonVegRestaurant();
    let nonVegMenu = v.getMenus();
    return nonVegMenu;
}

getVegNonMenu() {
    let v = new VegNonBothRestaurant();
    let bothMenu = v.getMenus();
    return bothMenu;
}

}

class VegMenu {} class NonVegMenu {} class Both {}

`

**Note: From this, It is clear that the complex implementation will be done by HotelKeeper himself. The client will just access the Hotel Keeper and ask for either Veg, NonVeg or VegNon Both Restaurant menu.

**How will the client program access this facade?

C++ `

package structural.facade;

public class Client { public static void main (String[] args) { HotelKeeper keeper = new HotelKeeperImplementation();

    VegMenu v = keeper.getVegMenu();
    NonVegMenu nv = keeper.getNonVegMenu();
    Both = keeper.getVegNonMenu();

}

}

Java

package structural.facade;

public class Client { public static void main (String[] args) { HotelKeeper keeper = new HotelKeeperImplementation();

    VegMenu v = keeper.getVegMenu();
    NonVegMenu nv = keeper.getNonVegMenu();
    BothMenu both = keeper.getVegNonMenu();
}

}

Python

from structural.facade import HotelKeeperImplementation, VegMenu, NonVegMenu, BothMenu

def main(): keeper = HotelKeeperImplementation() v = keeper.get_veg_menu() nv = keeper.get_non_veg_menu() both = keeper.get_veg_non_menu()

if name == "main": main()

JavaScript

const { HotelKeeperImplementation, VegMenu, NonVegMenu, BothMenu } = require('./structural/facade');

function main() { const keeper = new HotelKeeperImplementation(); const v = keeper.getVegMenu(); const nv = keeper.getNonVegMenu(); const both = keeper.getVegNonMenu(); }

main();

`

In this way, the implementation is sent to the facade. The client is given just one interface and can access only that. This hides all the complexities.

Advantages

The Facade Pattern simplifies interaction with complex systems by providing a unified and easy-to-use interface.

Disadvantages

While useful, the Facade Pattern can introduce limitations and additional abstraction in certain scenarios.