Bird
0
0

Which code structure correctly shows model-view separation in a game?

easy🧠 Conceptual Q12 of 15
LLD - Design — Tic-Tac-Toe Game
Which code structure correctly shows model-view separation in a game?
Aclass GameModel { int score; } class GameView { void draw(); }
Bclass Game { int score; void draw(); }
Cvoid draw() { int score; }
Dint score; void draw() { score++; }
Step-by-Step Solution
Solution:
  1. Step 1: Identify separation in code

    class GameModel { int score; } class GameView { void draw(); } separates game data (score) in GameModel and visuals (draw) in GameView.
  2. Step 2: Check other options

    Options A, C, and D mix logic and visuals in one place, breaking separation.
  3. Final Answer:

    class GameModel { int score; } class GameView { void draw(); } -> Option A
  4. Quick Check:

    Separate classes for model and view = class GameModel { int score; } class GameView { void draw(); } [OK]
Quick Trick: Look for separate classes for logic and visuals [OK]
Common Mistakes:
MISTAKES
  • Mixing data and drawing in one class
  • Putting logic inside drawing functions
  • Ignoring separation in code structure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes