O'Reilly logo

Java™ Design Patterns: A Tutorial by James W. Cooper

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 14. The Flyweight Pattern

In this chapter we take up the Flyweight pattern, which is used to avoid the overhead of large numbers of very similar classes.

Sometimes, you need to generate a very large number of small class instances to represent data. You can greatly reduce the number of different classes that you need to instantiate if you can determine that the instances are fundamentally the same, except for a few parameters. If you can move those variables outside of the class instance and pass them in as part of a method call, you greatly reduce the number of separate instances by sharing them.

The Flyweight pattern provides an approach for handling such classes. It refers to the instance's intrinsic data that make the instance unique ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required