Extending the Pattern: ○ The Flyweight Pattern could be extended to support composite objects where each flyweight can contain references to other flyweights. For example,
Short answer: complex character (e.g., with styling information) could consist of several flyweight components (like the base character, font style, size, etc.).
Explain a bit more
Visual Diagram: +---------------------------+ | CharacterFactory | | (Flyweight Factory) | +---------------------------+ +---------------------------------------------+ | | +------------------+ +------------------+ | Character | | Character | <--- Flyweight Objects | (Intrinsic State)| | (Intrinsic State)| +------------------+ +------------------+ | | | * Shared across all objects | +--------------------------------------------------->+ (Position, Size, Text displayed are external/unique) (Memory saved by sharing the intrinsic state) Conclusion: The Flyweight Pattern provides a powerful way to manage large numbers of similar objects efficiently by sharing common state and…
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png