The Flyweight Pattern Nik Reiman Joshua Hertz
Roadmap What is the Flyweight Pattern? UML When is Flyweight Useful? How to Use the Flyweight Pattern?
What is the Flyweight Pattern? As Defined By the Gang of 4 –Use Sharing to support large numbers of Fine-Grained objects efficiently. As Defined By Metsker –The Flyweight Pattern addresses sharing, relying on an objects ability to be responsible to more then one client.
A More Usable Definition Specifies a commonality among many objects Acts as independent object in each context Helps to share information among objects
UML Example
When is a Flyweight useful? Lots of small objects with a common inheritance –Word processor –Online book Independent central class
How to use Flyweight Extract the immutable part of central class Make this information static Provide this information to an arbitrary number of client objects
Example of Flyweight at Oozinoz (figure 13.2)
The Challenges The challenges are overly confusing (to us anyway). It’s worth your time to try them though.
Questions?