We can dynamically add responsibilities to objects with a component and decorator relationship. We’re able to add behavior to our classes by wrapping them up inside other classes. The decorator pattern allows us to add functionality to our classes without directly modifying or inheriting from them. If you don’t know what a wrapper class is, you might want to check out this post first! (But it’s not required) Overviewĭecorate: make (something) look more attractive by adding extra items or images to it. You’ll soon see that the decorator pattern gives our code flexibility at run-time while extending class functionality. When you think of the decorator pattern, think of Matryoshka dolls (the dolls that stack inside of one another).
Structural patterns give us a way of combining objects into larger structures while keeping these structures flexible and efficient. This time we’re going to be going over our first structural pattern, the decorator pattern.
Hey there, my last posts looked at creational and behavioral design patterns.