13 Flyweight

THE FLYWEIGHT PATTERN provides for sharing an object between clients, creating a responsibility for the shared object that normal objects need not consider. An ordinary object doesn’t have to worry much about shared responsibility. Most 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 ...

Get Design Patterns in Java™, Second Edition 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.