Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • System Design Tutorial
  • What is System Design
  • System Design Life Cycle
  • High Level Design HLD
  • Low Level Design LLD
  • Design Patterns
  • UML Diagrams
  • System Design Interview Guide
  • Scalability
  • Databases
Open In App
Next Article:
Composite Design Pattern | JavaScript Design Patterns
Next article icon

Facade Design Pattern | JavaScript Design Pattern

Last Updated : 31 Oct, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

Facade design pattern is a Structural design pattern that allows users to create a simple interface that hides the complex implementation details of the system making it easier to use. This pattern intends to create a simplified and unified interface for a set of interfaces hiding the implementation details making it less complex to use.


facade-design-pattern-javascript

Important Topics for the Facade Design Pattern in JavaScript Design Patterns

  • Components of the Facade Design Pattern
  • Implementation of the Facade design pattern using JavaScript
  • Advantages of the Facade Design Pattern in JavaScript Design Patterns
  • Disadvantages of the Facade Design Pattern in JavaScript Design Patterns

Components of the Facade Design Pattern

The components of the Facade design pattern include:

  • Subsystem: The Subsystem is a class or group of classes or interfaces that handles the entire complex logic and implementation.
  • Facade: The Facade is the class or object that serves as an entry point to the Subsystem's implementation hiding the complex implementation details.
  • Client: The Client interacts with the simplified Interface provided by Facade to perform operations without knowing the internal implementation details.

Implementation of the Facade design pattern using JavaScript

Let us understand the process of Implementing a Facade design pattern with an example:

Step 1: Creation of Subsystem

JavaScript
class SubsystemA {   method() {     console.log('This is a method of Subsystem-A');   } }  class SubsystemB {   method() {     console.log('This is a method of Subsystem-B');   } }  class SubsystemC {   method() {     console.log('This is a method of Subsystem-C');   } } 

Explanation:

In this step, I have created the Subsystem which contains three different classes namely `SubsystemA`, `SubsystemB` and` SubsystemC` along with the methods which console logs the information about which method they belong to.

Step 2: Creation of the Facade

JavaScript
class Facade {   constructor() {     this.subsystemA = new SubsystemA();     this.subsystemB = new SubsystemB();     this.subsystemC = new SubsystemC();   }    commonInterface() {     this.subsystemA.method();     this.subsystemB.method();     this.subsystemC.method();   } } 

Explanation:

In this step, I have created a `Facade` class that contains a constructor that intialies the objects of the three Substystems i.e. `SubsystemA`, `SubsystemB`, `SubsystemC` respectively. The `Facade` class is also responsible for providing a common interface. So, I created a method called `commonInterface` which hides the implementation details of subsystem and serves as a entry point.

Step 3: Usage and the Client code

JavaScript
const facade = new Facade(); facade.commonInterface(); 

Explanation:

In this step, I have created a `facade` object for the Facade class and calling the `commonInterface` method of the `Facade` class. Now, the actual process starts without need of knowing the implementation details.

Below is the complete code for the Facade Design Pattern in Javascript:

JavaScript
class SubsystemA {   method() {     console.log('This is a method of Subsystem-A');   } }  class SubsystemB {   method() {     console.log('This is a method of Subsystem-B');   } }  class SubsystemC {   method() {     console.log('This is a method of Subsystem-C');   } } class Facade {   constructor() {     this.subsystemA = new SubsystemA();     this.subsystemB = new SubsystemB();     this.subsystemC = new SubsystemC();   }    commonInterface() {     this.subsystemA.method();     this.subsystemB.method();     this.subsystemC.method();   } } const facade = new Facade(); facade.commonInterface(); 


Output:

Screenshot-(1210)
output


Below is the Diagrammatic Representation of the Facade Design Pattern:

Let's visualize the above example using UML components.


Facade-Design-Pattern-(1)

Advantages of the Facade Design Pattern in JavaScript Design Patterns

  • Simplified Interface: The Facade design pattern uses a simplified interface which helps the client to interact with and perform operations without knowing the implementation details.
  • Abstraction and Encapsulation: The Facade design pattern abstracts the internal implementation details and Encapsulates the Subsystem's logic.
  • Reduced Complexity: As the Facade design pattern hides the implementation details for the client, there is reduced complexity and cognitive load on the client. so, the client can focus on the system's working rather than the subsystem's implementation.
  • Improved Maintainability: As the common interface provided by the Facade class serves as an accessing entry point, it also acts as a centralized way to make changes to the subsystem, providing an easier way to maintain the subsystem.
  • Enhanced Reusability: The simplified interface provided by the facade makes it easier to reuse the subsystem across multiple parts of the application or in different applications.

Disadvantages of the Facade Design Pattern in JavaScript Design Patterns

  • Limited Functionality Exposure: The Facade design pattern may restrict the client from accessing the functionality of certain operation of the subsystem without knowing the actual implementation details.
  • Potential Performance Overhead: In some cases, Relying on the facade design pattern may lead to Performance overhead due to the additional layer of Abstraction.
  • Potential Design Misuse: In some cases, taking the advantage of hiding the implementation details developers may hide up the poor implementation or design issues.

Next Article
Composite Design Pattern | JavaScript Design Patterns

T

thoughtscj6os
Improve
Article Tags :
  • Design Pattern
  • Geeks Premier League
  • System Design
  • Geeks Premier League 2023
  • JavaScript Design Patterns

Similar Reads

  • JavaScript Design Patterns Tutorial
    Design patterns in Javascipt are communicating objects and classes that are customized to solve a general design problem in a particular context. Software design patterns are general, reusable solutions to common problems that arise during the design and development of software. They represent best
    8 min read
  • Creational Software Design Patterns in JavaScript

    • Builder Method | JavaScript Design Pattern
      The Builder design pattern is a creational design pattern used to construct complex objects by separating the construction process from the actual representation. It's especially useful when an object requires multiple steps or configurations to be created. Important Topics for the Builder Design Pa
      9 min read
    • Prototype Method - JavaScript Design Pattern
      A Prototype Method is a JavaScript design pattern where objects share a common prototype object, which contains shared methods. The prototype method allows you to reuse the properties and methods of the prototype object, and also add new ones as needed. The prototype method is useful for performance
      3 min read
    • Abstract Factory Pattern | JavaScript Design Patterns
      Abstract Factory Pattern is to abstract the process of object creation by defining a family of related factory methods, each responsible for creating a different type of object. These factory methods are organized within an abstract factory interface or class, and the client code uses this interface
      6 min read
    • Behavioural Software Design Patterns in JavaScript

      • Template Method | JavaScript Design Patterns
        Template Method is a behavioral design pattern that defines the skeleton of an algorithm in a base class while allowing subclasses to implement specific steps of the algorithm without changing its structure. It promotes code reusability and provides a way to enforce a consistent algorithm structure
        10 min read
      • State Method Design Patterns in JavaScript
        State method or State Design Patterns is a pattern that allows an object to alter its behavior when internal state changes occur. This pattern is used when an object wants to change its state dynamically. When we want to change behavior of object it internally uses if-else block to perform actions.
        4 min read
      • Iterator Method | JavaScript Design Pattern
        Iterator design pattern is a behavioral design pattern that provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation. It separates the responsibility of accessing and traversing the elements from the aggregate object. This pattern is wi
        4 min read
      • Strategy Method | JavaScript Design Pattern
        Strategy Method or Strategy Pattern in JavaScript helps solve the problem of needing to use different methods or behaviors in your code and easily switch between them. Strategy Method is a behavioral design pattern in JavaScript that defines a family of algorithms, encapsulates each one, and makes t
        8 min read
      geeksforgeeks-footer-logo
      Corporate & Communications Address:
      A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
      Registered Address:
      K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
      GFG App on Play Store GFG App on App Store
      Advertise with us
      • Company
      • About Us
      • Legal
      • Privacy Policy
      • In Media
      • Contact Us
      • Advertise with us
      • GFG Corporate Solution
      • Placement Training Program
      • Languages
      • Python
      • Java
      • C++
      • PHP
      • GoLang
      • SQL
      • R Language
      • Android Tutorial
      • Tutorials Archive
      • DSA
      • Data Structures
      • Algorithms
      • DSA for Beginners
      • Basic DSA Problems
      • DSA Roadmap
      • Top 100 DSA Interview Problems
      • DSA Roadmap by Sandeep Jain
      • All Cheat Sheets
      • Data Science & ML
      • Data Science With Python
      • Data Science For Beginner
      • Machine Learning
      • ML Maths
      • Data Visualisation
      • Pandas
      • NumPy
      • NLP
      • Deep Learning
      • Web Technologies
      • HTML
      • CSS
      • JavaScript
      • TypeScript
      • ReactJS
      • NextJS
      • Bootstrap
      • Web Design
      • Python Tutorial
      • Python Programming Examples
      • Python Projects
      • Python Tkinter
      • Python Web Scraping
      • OpenCV Tutorial
      • Python Interview Question
      • Django
      • Computer Science
      • Operating Systems
      • Computer Network
      • Database Management System
      • Software Engineering
      • Digital Logic Design
      • Engineering Maths
      • Software Development
      • Software Testing
      • DevOps
      • Git
      • Linux
      • AWS
      • Docker
      • Kubernetes
      • Azure
      • GCP
      • DevOps Roadmap
      • System Design
      • High Level Design
      • Low Level Design
      • UML Diagrams
      • Interview Guide
      • Design Patterns
      • OOAD
      • System Design Bootcamp
      • Interview Questions
      • Inteview Preparation
      • Competitive Programming
      • Top DS or Algo for CP
      • Company-Wise Recruitment Process
      • Company-Wise Preparation
      • Aptitude Preparation
      • Puzzles
      • School Subjects
      • Mathematics
      • Physics
      • Chemistry
      • Biology
      • Social Science
      • English Grammar
      • Commerce
      • World GK
      • GeeksforGeeks Videos
      • DSA
      • Python
      • Java
      • C++
      • Web Development
      • Data Science
      • CS Subjects
      @GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
      We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
      Lightbox
      Improvement
      Suggest Changes
      Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
      geeksforgeeks-suggest-icon
      Create Improvement
      Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
      geeksforgeeks-improvement-icon
      Suggest Changes
      min 4 words, max Words Limit:1000

      Thank You!

      Your suggestions are valuable to us.

      What kind of Experience do you want to share?

      Interview Experiences
      Admission Experiences
      Career Journeys
      Work Experiences
      Campus Experiences
      Competitive Exam Experiences