Flyweight

Description

Manage large numbers of fine-grained objects by sharing to improve efficiency.
More info

Profile

UML profile of design pattern

Profile download (Rational Rose model)

OCL Constraints

context Flyweight
inv: self.isRoot implies (self.isAbstract and self.fFT->size() = 1)

inv: self.isAbstract implies (self.specialization->size() > 0 and
self.specialization->forAll (c | c.child.oclIsKindOf (Flyweight)))

inv: not self.isAbstract implies self.cFF->size() = 1

context aFlyweightFactory
inv: self.fFT.isNavigable and not self.fFY.isNavigable and
self.fFY.aggregation = AggregationKind::aggregate

context aClientFlyweight
inv: self.cFF.isNavigable and not self.cFC.isNavigable

context aClientFlyFactory
inv: self.cFFY.isNavigable and not self.cFFT.isNavigable
	

Explanation of Profile

  1. There is a flyweight class hierarchy with an abstract base class that defines some operations that has some extrinsic state as parameters.
  2. The base flyweight class has some conrete sub-classes that a client has unidirectional associations with.
  3. The client also has a unidirectional association with a flyweight factory, which has operations to create flyweight objects.
  4. The flyweight factory has a unidirectional aggregate association with the base flyweight class.
  5. Concrete flyweights may have intrinsic states.
  6. The profile does not make distinctions between shared and unshared concrete flyweights.

Correct Instance

correct design pattern instance

Incorrect Instance

incorrect design pattern instance

This instance, even though correct in another interpretation of the pattern, is incorrect in our profile because there is no flyweight class hierarchy with an abstract base class.

Tool Output

output of tool