Comparison
FlyweightvsIntrinsic state
Flyweight
a million objects turned into a thousand shared ones plus a million positions, because most of the data was identical.
Sharing one immutable instance across many logical objects by splitting the data that is common from the data that is not. Almost nobody implements it deliberately today, but everyone uses it: string interning, boxed integer caches, glyph and texture caches are all flyweights. It earns its place in this corpus because it is asked about in interviews and because recognising it explains why two identical small integers can be reference-equal in some languages.
Full entry →Intrinsic state
the character knows its glyph and not its position, because the position was moved out to the caller.
The split that makes a flyweight possible: intrinsic state is context-free and shareable, extrinsic state is passed in by the caller for the duration of an operation. Naming the split is the useful part, because it is a general technique — pushing context out of an object to make it shareable, cacheable or thread-safe applies well beyond the pattern. It is also the reason a flyweight has to be immutable.
Full entry →