The Decorator is one of those rare patterns where the name represents its purpose perfectly. As its name implies, the Decorator pattern permits us to decorate an object; this is, of course, a very vague explanation. So, a more concrete but simple explanation of its core purpose is that it offers us a way to decorate old code with new code, by dynamically adding functionality to an object.
The following topics will be covered in this chapter:
- We will review the basics of the Decorator pattern
- We will build a system to add attachments to a rifle dynamically