Build a Shared Glyph Cache
Flyweight pattern
Challenge 6 of Create & Share ObjectsIntermediate~55 minFree
Build a text renderer with the Flyweight pattern: share one immutable Glyph object per character across every position it appears, and pass position (extrinsic state) in per render call. You will grow a GlyphFactory cache, prove object identity is reused, keep extrinsic state out of the shared object, lay out a whole document with shared glyphs, and finally key the cache by (char, style) so styled variants stay separate.