Challenge: Decorator Pattern
In this challenge, you have to implement the decorator pattern to solve the given problem.
We'll cover the following
Problem statement
The code below implements the functionality that customizes superheroes for a game. If you study the code below, you’ll see that every superhero has a power
. However, you can also create superheroes that have the following in addition to the power
:
-
a sword
-
super speed
-
a sword and super speed
Run the code below to see its implementation:
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.