Chapter 13. Flyweight

The flyweight pattern addresses sharing, relying on an object's ability to be responsible to more than a single client. An ordinary object doesn't have to worry much about shared responsibility. Often, only one client will hold a reference to an object at any one time. When the object's state changes, it's because the client changed it, and the object does not have any responsibility to inform any other clients. Sometimes, though, you will want to arrange for multiple clients to share access to an object.

One incentive for sharing an object among multiple clients occurs when you must manage thousands or tens of thousands of small objects, such as the characters in an online version of a book. In such a case, you may have ...

Get Design Patterns Java™ Workbook 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.