Multiple choice technology programming languages

When would you use the Flyweight pattern?

  1. When you need classes to be notified of events but you don't know which classes or if you will need to add more at a later date.

  2. When the instances of your class can be used interchangeably and you want to reduce the number of instances created in order to improve performance.

  3. When the instances of your class cannot be used interchangeable and you need to convert them so that they are interchangeable

  4. When the instances of your class can be use interchangeable and you want to reduce the number of instances created in order to improve performance

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Flyweight reduces memory by sharing intrinsic state among many objects. Objects must be interchangeable (same behavior) so instances can be shared freely. When instances differ in behavior, they can't be shared - Flyweight doesn't apply. Option B captures both conditions: interchangeability + performance via sharing.