The Flyweight pattern reduces the number of low-level, detailed objects within a system by sharing objects. If instances of a class that contain the same information can be used interchangeably, the Flyweight pattern allows a program to avoid the expense of multiple instances that contain the same information by sharing one instance.
The following lists the benefits of using the Flyweight pattern:
- Reduction in the number of objects to handle
- Reduction in memory and on storage devices, if the objects are persisted
You should use the Flyweight pattern when all of the following are true:
- The application uses a large number of objects.
- Storage costs are high because of the quantity of objects.
- The application doesn’t depend on object identity.