Bird
Raised Fist0

When extending the Snake and Ladder game to support teleportation cells that send players to random positions, which design approach best handles this without breaking existing snake and ladder logic?

hard⚖️ Approach Comparison Q8 of Q15
OOP & Design Patterns - Design Snake and Ladder Game - LLD End-to-End
When extending the Snake and Ladder game to support teleportation cells that send players to random positions, which design approach best handles this without breaking existing snake and ladder logic?
AAdd teleportation logic inside the GameBoard class alongside snakes and ladders
BCreate a new Cell interface with subclasses for SnakeCell, LadderCell, TeleportCell
CModify Player class to check for teleportation after every move
DUse a global event listener to handle teleportation events
Step-by-Step Solution
Solution:
  1. Step 1: Identify extensibility need

    New cell types require flexible design without modifying existing logic.
  2. Step 2: Use polymorphism

    Cell interface with subclasses allows adding new behaviors cleanly.
  3. Step 3: Evaluate other options

    Adding logic in GameBoard mixes concerns; Player checking breaks encapsulation; global listener adds unnecessary complexity.
  4. Final Answer:

    Option B -> Option B
  5. Quick Check:

    Polymorphism supports extensibility [OK]
Quick Trick: Polymorphism for new cell types [OK]
Common Mistakes:
MISTAKES
  • Mixing new logic into GameBoard
  • Adding responsibilities to Player
  • Using event listeners unnecessarily
Trap Explanation:
PITFALL
  • Candidates often choose quick fixes that break separation of concerns instead of clean polymorphic design.
Interviewer Note:
CONTEXT
  • Assesses ability to design extensible and maintainable systems
Master "Design Snake and Ladder Game - LLD End-to-End" in OOP & Design Patterns

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More OOP & Design Patterns Quizzes