Flyweight Design Pattern


GoF Statement: Uses sharing to support large numbers of fine-grained objects efficiently.
Category: Structural
UML Diagram:  

Description of the Demonstration:

This demonstration simulates a landscape design application that places any number of "trees and shrubs" on a lot. Rather than instantiate a large number of instances of Tree, all of which differ only in the location and age (controlling the size it is drawn), a single instance of Tree is created and then the TreeManager keeps the information on the location and age of each "instance" of Tree.


Code:

Click here to download a zip file containing all the source files and an executable of the Demonstration. See the _ReadMe.txt file in the zip.