All challenges
intermediateDesign Patterns~55 min

Shared Glyphs (Flyweight Pattern)

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.