Design: Flyweight Pattern Implementation
Design the Flyweight pattern structure and usage for a system that needs many similar objects with shared state. Out of scope: specific application domain details or UI integration.
Functional Requirements
FR1: Support creation of many similar objects efficiently
FR2: Share common intrinsic state among objects to save memory
FR3: Allow extrinsic state to be supplied externally when needed
FR4: Provide a way to manage and reuse shared objects
FR5: Ensure thread-safe access to shared objects if used concurrently
Non-Functional Requirements
NFR1: Must reduce memory usage significantly compared to naive object creation
NFR2: Should not compromise performance when accessing shared objects
NFR3: Design should be simple to integrate into existing systems
NFR4: Support up to 1 million objects with limited memory overhead
NFR5: Latency for object retrieval should be under 5ms