Challenge: Bridge Pattern
In this challenge, you have to implement the bridge pattern to solve the given problem.
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:
To further clarify, the code above has one parent class Applications and four child classes:
-
FacebookLightMode -
FacebookDarkMode -
WhatsAppLightMode -
WhatsAppDarkMode
You can see that two major things define these classes:
-
the application name
-
the color mode of the application
Your task is to modify the code using the bridge pattern so that the code can be run as follows:
Input
Calling light mode/dark mode methods for an application
Output
The message displayed on switching to a specific color mode
Sample input
const fb = new Facebook("Facebook", "Social Networking")
const mode = new Mode(fb)
mode.darkMode()
fb.displayMode()
const whatsapp = new WhatsApp("Whatsapp", "Chatting")
const mode2 = new Mode(whatsapp)
mode2.lightMode()
whatsapp.displayMode()
Sample output
"You are using facebook in dark mode."
"You are using whatsapp in light mode."
Challenge #
Take a close look and design a step-by-step solution before jumping on to the implementation. This problem is designed for your practice, so try to solve it on your own first. If you get stuck, you can always refer to the solution provided. Good Luck!
Let’s discuss the solution in the next lesson.