Challenge: Solution Review
Understand how to optimize app mode management using the bridge pattern in JavaScript structural design patterns. This lesson reviews solution improvements by separating application modes from the app classes, reducing class duplication, and enabling flexible mode switching. Learn to implement and apply this pattern effectively for coding interviews.
We'll cover the following...
Solution #
Explanation
Let’s start by looking at the code we had originally:
As you can see, there is a parent class Applications. It has four child classes:
-
FacebookLightMode -
FacebookDarkMode -
WhatsAppLightMode -
WhatsAppDarkMode
The definitions of these classes are simple. Apart from initializing the application name and type, each class also defines the following functions:
-
display -
displayMode
Each class has its definition of both these ...