What is the difference between intrinsic and extrinsic state in the Flyweight pattern, and why does that distinction matter for memory usage?
Intrinsic state is the part of an object's data that is identical across many instances -- for example, a bullet's color or its rendered image -- and it can safely be extracted into one shared object stored exactly once. Extrinsic state is the part that is genuinely unique to each individual instance, such as a bullet's x and y position, and it must stay with each object individually since it cannot be shared. The distinction matters because Flyweight's entire memory saving comes from paying the cost of intrinsic state once per unique value instead of once per object, while extrinsic state stays cheap because it is usually just a few primitive fields. Get the split wrong -- for example, sharing something that should have been per-instance -- and objects that should behave independently will start silently affecting each other.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response