Applied Design Patterns with Java
Structural :: Flyweight (195) {C ch 14}
Example - UML : Folders
Example - Java :: Patterns\Structural\Flyweight
Pattern Concept: to avoid the overhead of large numbers of very similar classes, and to correspondingly
reduce the object instance count.
Issues and Consequences of the Flyweight pattern include:
- A Flyweight is a sharable instance of a class. If extrinsic data can be moved out of a class without affecting its use, it
is probably a Flyweight, not a Singleton;
- Flyweight instrinsic data is unique to the instance and sharable; extrinsic
data is not shared or otherwise not unique to the instance - extrinsic data maintained inside of instances unnecessarily
increases the class and instance count;
- Flyweights are not often used in Java applications,
but they are frequently used in Java system resource management programs;
- Sharable objects
in general, and Flyweights in particular, may require intense work to properly synchronize them in
a multi-threaded environment.
- 'Copy-on-Write' object versioning can be added to Flyweights with the added use of the Proxy pattern.
The example Java program is named 'FlyCanvas'. The UML
diagram is above, and the list of Java files is below:
Catalog Structural Prev Next