Separate shared immutable state from caller-supplied context so Java flyweights stay reusable, memory-efficient, and conceptually clean.
Intrinsic state: The part of a flyweight that can be shared safely across uses.
Extrinsic state: The context the caller supplies for each use because it should not be stored in the shared object.
This distinction is the center of the Flyweight pattern. If the boundary is wrong, the pattern collapses.
flowchart LR
A["Client"] --> B["Supplies extrinsic state"]
B --> C["Flyweight"]
C --> D["Intrinsic state kept inside"]
B --> E["Position, request context, owner, or timestamp kept outside"]
Intrinsic state should be:
Examples:
Extrinsic state usually depends on one use site:
If that state is stored inside the shared flyweight, the flyweight stops being safely reusable.
When deciding whether something is intrinsic, ask:
If the answer is no, the state is probably extrinsic.