Chapter    14

The Decorator Pattern

In this chapter, I describe the decorator pattern, which allows the behavior of an object to be selectively modified at runtime. This pattern has a number of uses but has the most impact when working with classes that cannot be modified. The idea of selective modification means that you can choose which objects are changed and which retain their original functionality. Table 14-1 puts the decorator pattern into context.

Table 14-1. Putting the Decorator Pattern into Context

Question

Answer

What is it?

The decorator pattern allows the behavior of individual objects to be changed without requiring changes to the classes that are used to create them or the components that consume them.

What are the benefits?

The changes ...

Get Pro Design Patterns in Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.