Facade Design Pattern

Facade Design Pattern is the Structural design patterns (like Adapter pattern and Decorator pattern). Facade design pattern is used to easily interact with the complex system.

According to Design Patterns: Elements of Reusable Object-Oriented Software (Gang of Four) Facade design pattern is:

Provide a unified interface to a set of interfaces in a subsystem. Facade Pattern defines a higher-level interface that makes the subsystem easier to use.

Continue reading “Facade Design Pattern”

DECORATOR DESIGN PATTERN

Let’s imagine we want to create a game, and for our superhero, we want to add a new gadget to every level of the game and gadget should be selected by the player.

How we can do that?🤔

One way to do that use traditional inheritance, We will create a base abstract gadget class and multiple subclasses for different gadget combination.

But wait I have n numbers of gadgets so in my case I have to create n! subclasses.

If n = 5 then for 5 powers the number of subclasses will be 5! = 120. For 5 gadget we have to create 120 subclasses.😢

Is there any other simple way to do that?

Yes, We can use Decorator Design Pattern to solve this problem.

Decorator Design Pattern allows behavior to be added to an individual object, either statically or dynamically, without affecting the behavior of other objects from the same class

Continue reading “DECORATOR DESIGN PATTERN”