Flyweight Pattern
Learn Flyweight Pattern (Structural Patterns, Design Patterns in Java) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
The Flyweight Pattern reduces memory usage by sharing common state across many similar objects instead of storing that state redundantly in each one. Real-Life Example: A text editor - every occurrence of the letter "A" in a document can share ONE glyph/font object instead of each character owning its own copy A game with thousands of trees on a map - the 3D model/texture (shared) is reused; only each tree's x/y position (unique) is stored per instance Intrinsic vs Extrinsic State Intrinsic state - shared, immutable, stored once inside the flyweight object (e.g. the character's font/shape)...