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

Get Hands-On Game Development Patterns with Unity 2019 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.