Bird
0
0

Which scenario best demonstrates the use of the Null Object pattern?

easy🧠 Conceptual Q2 of 15
LLD - Behavioral Design Patterns — Part 2
Which scenario best demonstrates the use of the Null Object pattern?
AThrowing an exception when a null value is encountered.
BReturning a special object instead of null to avoid conditional checks.
CLogging an error message when a null is found.
DUsing a global variable to store null values.
Step-by-Step Solution
Solution:
  1. Step 1: Identify what Null Object pattern does

    It returns a special object that behaves safely instead of returning null.
  2. Step 2: Compare options

    Throwing exceptions or logging errors are error handling, not Null Object usage. Using global variables for null is unrelated.
  3. Final Answer:

    Returning a special object instead of null to avoid conditional checks. -> Option B
  4. Quick Check:

    Null Object usage = Return special object [OK]
Quick Trick: Null Object returns safe object, not null [OK]
Common Mistakes:
MISTAKES
  • Confusing error handling with Null Object pattern
  • Thinking Null Object throws exceptions
  • Using global variables for null management

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes