Bird
0
0

Identify the error in this model-view separation code:

medium📝 Analysis Q14 of 15
LLD - Design — Tic-Tac-Toe Game
Identify the error in this model-view separation code:
class Model { int health = 100; void damage(int d) { health -= d; } } class View { void show() { print("Health: " + health); } }
ANo error, code is correct.
BModel class should not have damage method.
CView class should update health value.
DView class cannot access 'health' directly from Model.
Step-by-Step Solution
Solution:
  1. Step 1: Check access between classes

    The View class tries to print 'health' but does not have access to Model's health variable.
  2. Step 2: Understand separation rules

    View should get health value from Model via method or parameter, not direct access.
  3. Final Answer:

    View class cannot access 'health' directly from Model. -> Option D
  4. Quick Check:

    View needs data from Model, no direct access [OK]
Quick Trick: View must get data from Model, not access variables directly [OK]
Common Mistakes:
MISTAKES
  • Assuming View can access Model variables directly
  • Thinking Model should not have methods
  • Believing View should modify Model data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes