22. Flyweight
The Flyweight pattern minimizes the amount of memory and/or processor overhead required to use objects. The advantages of object-oriented programming are sometimes outweighed by the overhead of using objects particularly when large numbers of object instances are needed at once. The Flyweight pattern enables instance sharing to reduce the number of instances needed while preserving the advantages of using objects. Classes that implement the Flyweight pattern are called “flyweights.”
Motivation
Within Cocoa, flyweights are primarily used for the following three reasons:
• Flyweights encapsulate nonobject data so that the data can be used in contexts where objects are required.
• Flyweights reduce storage requirements when a large ...
Get Cocoa Design Patterns 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.