Challenge: Bridge Pattern
In this challenge, you have to implement the bridge pattern to solve the given problem.
We'll cover the following...
Problem statement
Study the code given below and its output. Carefully look at the classes defined and try to understand the purpose of the program.
Press + to interact
class Applications{constructor(name, type){this.name = namethis.type = type}display(){}displayMode(){}}class FacebookLightMode extends Applications{constructor(name,type){super(name,type)}display(){console.log(`Welcome to Facebook for ${this.type}.`)}displayMode(){console.log("You are using facebook in light mode.")}}class FacebookDarkMode extends Applications{constructor(name,type){super(name,type)}display(){console.log(`Welcome to Facebook for ${this.type}.`)}displayMode(){console.log("You are using facebook in dark mode.")}}class WhatsAppLightMode extends Applications{constructor(name,type){super(name,type)}display(){console.log(`Welcome to Whatsapp for ${this.type}.`)}displayMode(){console.log("You are using whatsapp in light mode.")}}class WhatsAppDarkMode extends Applications{constructor(name,type){super(name,type)}display(){console.log(`Welcome to Whatsapp for ${this.type}.`)}displayMode(){console.log("You are using whatsapp in dark mode.")}}const fbLight = new FacebookLightMode("Facebook", "Social Networking")const whatsappDark = new WhatsAppDarkMode("Whatsapp", "Chatting")fbLight.display()fbLight.displayMode()whatsappDark.display()whatsappDark.displayMode()
To further clarify, the code above has one parent class Applications
and four child classes:
-
FacebookLightMode
-
FacebookDarkMode
-
WhatsAppLightMode
...