Bird
0
0

Which of the following is the correct way to define a state interface in a typical State pattern implementation?

easy🧠 Conceptual Q12 of 15
LLD - Behavioral Design Patterns — Part 1
Which of the following is the correct way to define a state interface in a typical State pattern implementation?
Ainterface State { void handle(); }
Bclass State { void handle() {} }
Cenum State { START, STOP }
Dstruct State { int status; }
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct interface syntax

    The State pattern requires a State interface with a method like handle() to define behavior.
  2. Step 2: Eliminate incorrect options

    class State { void handle() {} } is a class, not an interface; C is an enum, not behavior; D is a struct without behavior.
  3. Final Answer:

    interface State { void handle(); } -> Option A
  4. Quick Check:

    State interface defines behavior method [OK]
Quick Trick: State pattern needs interface with behavior method [OK]
Common Mistakes:
MISTAKES
  • Using enum or struct instead of interface/class for behavior
  • Defining empty methods without interface
  • Confusing class and interface roles

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes