23. Decorators
The Decorators pattern adds common reusable capabilities to objects via composition as an alternative to adding capabilities via subclassing. Decorators can be added or configured at runtime in contrast to defining subclasses at compile time. Cocoa’s NSScrollView class is a prominent example of the Decorator pattern. Scrolling is a technique that enables users to control which portion of an object is visible when the object is too large to see in its entirety. Rather than reimplement scrolling capability in every object that draws, Cocoa provides scrolling by decorating objects with an NSClipView instance, which in turn is decorated by an NSScrollView instance. The NSClipView hides portions of the view it decorates. The NSScrollView ...
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