Advantages and Disadvantages
Developers enjoy using this pattern, as it can be used transparently and is also fairly flexible: as we’ve seen, objects can be wrapped or “decorated” with new behavior and then continue to be used without needing to worry about the base object being modified. In a broader context, this pattern also allows us to avoid relying on large numbers of subclasses to get the same benefits.
There are however drawbacks that we should be aware of when implementing the pattern. If poorly managed, it can significantly complicate our application architecture, as it introduces many small but similar objects into our namespace. The concern here is that, in addition to becoming hard to manage, other developers unfamiliar with the pattern may have a hard time grasping why it’s being used.
Sufficient commenting or pattern research should assist with the latter; however, as long as we keep a handle on how widespread we use the decorator in our applications, we should be fine on both counts.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access