Bird
0
0

Which of the following code examples correctly demonstrates model-view separation in a game?

easy🧠 Conceptual Q3 of 15
LLD - Design — Tic-Tac-Toe Game
Which of the following code examples correctly demonstrates model-view separation in a game?
Aclass View { int score; void update() { score++; } } class Model { void display() { print(score); } }
Bclass ModelView { int score; void update() { score++; print(score); } }
Cclass Model { int health; void damage() { health--; } } class View { void render(Model m) { print(m.health); } }
Dclass Model { int score; void display() { print(score); } } class View { void update() { score++; } }
Step-by-Step Solution
Solution:
  1. Step 1: Identify separation

    Model holds data and logic; View handles display using model data.
  2. Step 2: Analyze options

    class Model { int health; void damage() { health--; } } class View { void render(Model m) { print(m.health); } } cleanly separates model logic and view rendering.
  3. Final Answer:

    class Model { int health; void damage() { health--; } } class View { void render(Model m) { print(m.health); } } correctly shows model-view separation.
  4. Quick Check:

    Model updates data; view reads data to render [OK]
Quick Trick: Model holds data; view reads data to display [OK]
Common Mistakes:
MISTAKES
  • Combining model and view in one class
  • View modifying model data
  • Model handling rendering

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes