Design patterns Facade

Real world facade (C#)

public class MyDataExporterToExcell
    public static void Main()
        GetAndExportExcelFacade facade = new GetAndExportExcelFacade();


public class GetAndExportExcelFacade

    // All services below do something by themselves, determine location for data,
    // get the data, format the data, and export the data
    private readonly DetermineExportDatabaseService _determineExportData = new DetermineExportDatabaseService();
    private readonly GetRawDataToExportFromDbService _getRawData = new GetRawDataToExportFromDbService();
    private readonly TransformRawDataForExcelService _transformData = new TransformRawDataForExcelService();
    private readonly CreateExcelExportService _createExcel = new CreateExcelExportService();

    // the facade puts all the individual pieces together, as its single responsibility.
    public void Execute()
        var dataLocationForExport = _determineExportData.GetDataLocation();
        var rawData = _getRawData.GetDataFromDb(dataLocationForExport);
        var transformedData = _transformData.TransformRawToExportableObject(rawData);

Facade example in java

Facade is structural design pattern. It hides the complexities of large system and provides a simple interface to client.

Client uses only Facade and it's not worried about inter dependencies of sub-systems.

Definition from Gang of Four book:

Provide a unified interface to a set of interfaces in a subsystem. Fa├žade defines a higher-level interface that makes the subsystem easier to use


enter image description here

Real world example:

Think of some travel booking sites like makemytrip, cleartrip which offers services to book Trains, Flights and Hotels.

Code snippet:

import java.util.*;

public class TravelFacade{
    FlightBooking flightBooking;
    TrainBooking trainBooking;
    HotelBooking hotelBooking;

    enum BookingType {
    public TravelFacade(){
        flightBooking = new FlightBooking();
        trainBooking = new TrainBooking();
        hotelBooking = new HotelBooking();        
    public void book(BookingType type, BookingInfo info){
            case Flight:
                // book flight;
            case Hotel:
                // book hotel;
            case Train:
                // book Train;
            case Flight_And_Hotel:
                // book Flight and Hotel
             case Train_And_Hotel:
                // book Train and Hotel
class BookingInfo{
    String source;
    String destination;
    Date    fromDate;
    Date     toDate;
    List<PersonInfo> list;
class PersonInfo{
    String name;
    int       age;
    Address address;
class Address{

class FlightBooking{
    public FlightBooking(){
    public void bookFlight(BookingInfo info){
class HotelBooking{
    public HotelBooking(){
    public void bookHotel(BookingInfo info){
class TrainBooking{
    public TrainBooking(){
    public void bookTrain(BookingInfo info){


  1. FlightBooking, TrainBooking and HotelBooking are different sub-systems of large system : TravelFacade

  2. TravelFacade offers a simple interface to book one of below options

    Flight Booking
    Train Booking 
    Hotel Booking
    Flight + Hotel booking 
    Train + Hotel booking
  3. book API from TravelFacade internally calls below APIs of sub-systems

  4. In this way, TravelFacade provides simpler and easier API with-out exposing sub-system APIs.

Applicability and Use cases (from Wikipedia) :

  1. A simple interface is required to access a complex system.
  2. The abstractions and implementations of a subsystem are tightly coupled.
  3. Need an entry point to each level of layered software.
  4. System is very complex or difficult to understand.