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 ...
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