CS FundamentalsHardProduct-company design interview

A game renders 1,000,000 trees. Each tree object stores mesh and texture data (about 2 MB, the same for every oak) plus its own x, y position. Which pattern cuts memory, and what is shared?

  1. A. Flyweight: the mesh and texture (intrinsic state) are shared by all oaks, while position (extrinsic state) is kept per tree or passed in
  2. B. Prototype: each tree is cloned from one oak
  3. C. Singleton: there is only one tree object
  4. D. Proxy: trees are loaded lazily

Correct answer: A. Flyweight: the mesh and texture (intrinsic state) are shared by all oaks, while position (extrinsic state) is kept per tree or passed in

Flyweight splits state into intrinsic (shared, immutable) and extrinsic (context-specific) parts. Cloning with Prototype would still copy 2 MB per tree.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic