- What to look for: many objects instances
- Intent: sharing as much as data as possible across multiple objects in order to save as much memory as possible
- Logic
- Intrinsic state: data that is independet of the object context and is shared across objects
- Extrinsic state: unique to each object. Must be passed onto an object via argument passing when calling a method
- The intrinsic state is an object attribute (via composition) (possibly recycled from a pool). Whole object has the instrinic component plus its own extrensic stuff
- Components
- Flyweight ⇒ creates all extrinsic components. Data and methods are stored there for extrinsic part
- Flyweight factory ⇒ creates and manages flyweight objects (retrieving from a Map, for instance)
- Context (the actual, initially-intended object)⇒ full object, contains extrinsic part
- Flow
- Flyweight defines methods and attributes to be filled in
- Flyweight factory creates one such intrinsic using mapping logic
- Context creates the flywieght via the flywieght factory
- Code