Friday, April 20, 2007

Flyweight

The Flyweight patterns can be illustrated with the following figure:

In this figure, the Flyweight objects can be divided into two subgroups, according to the states they keep track of. ConcreteFlyweight ones only keep an intrinsic state and the extrinsic state should be computed to locate each one by the Client. It trades off the time cost to the storage cost. Usually, it should be those objects repeated frequently and larged whose extrinsic states are easy to obtained. The UnsharedConcreteFlyweight objects are usually those whose extrinsic states are also stored and won't be necessary to be kept in a pool (since they are seldom repeated).

Sometimes, Flyweight pattern is used with Composite, which then builds a complex objects by these small repeated ones.

No comments: