TechnologyZer
technologyzer.com

Facade Design Pattern

Facade design pattern simplifies interactions with a complex system by providing a unified interface.

Imagine planning a trip involves many complex steps like booking flights, hotels, and tour. Instead of dealing with each step individually, you use a travel agency as a “facade”. You tell the travel agent your preferences, and they handle all the details for you, simplifying the process. Behind the scenes, the travel agency deals with airlines, hotels, and tour operators, but for you, planning the trip becomes much easier because you only interact with the travel agent. This is similar to how the Facade Design Pattern simplifies interactions with complex systems by providing a unified interface.

5 real world example of Facade Design Pattern

Online Food Ordering Platform: Providing customers with a unified interface to browse restaurants, place orders, and make payments across multiple eateries.
Asset Management Software: Offering investors a streamlined interface to track and manage their investment portfolios, including stocks, bonds, and real estate holdings.
Integrated Health Monitoring Systems: Presenting healthcare professionals with a centralized dashboard to monitor patient vital signs, lab results, and medical history.
Mobile Banking Applications: Offering customers an intuitive interface to access banking services like account balance inquiries, fund transfers, and bill payments.
Online Learning Platforms: Providing students with a user-friendly portal to access course materials, submit assignments, and interact with instructors.

Class Diagram


~:Sample code of Facade Design Pattern:~

class Flight {
    public void bookFlight() {
        System.out.println("Booking a Flight for you...!!");
    }
}

class Hotel {
    public void bookHotel() {
        System.out.println("Booking a Hotel for you..!!");
    }
}

class Activities {
    public void bookActivity() {
        System.out.println("Booking an activity for you..!!");
    }
}

// Facade class
class TravelAgent {
    private Flight flight;
    private Hotel hotel;
    private Activities activities;


    public TravelAgent() {
        this.flight = new Flight();
        this.hotel = new Hotel();
        this.activities = new Activities();
    }

    public void start() {
        flight.bookFlight();
        hotel.bookHotel();
        activities.bookActivity();
        System.out.println("Congratulation..! You trip planning is successful..!");
    }
}

public class Main {
    public static void main(String[] args) {
        // Using the Facade to start the computer
        TravelAgent travelAgent = new TravelAgent();
        travelAgent.start();
    }
}

Leave a Comment