Bird
Raised Fist0

You are designing a notification system where some users may not want notifications. How can the Null Object pattern help here?

hard📝 Trade-off Q8 of Q15
LLD - Behavioral Design Patterns — Part 2
You are designing a notification system where some users may not want notifications. How can the Null Object pattern help here?
AProvide a NullNotifier that implements notify but does nothing, avoiding null checks.
BThrow exceptions when notifications are disabled.
CUse a global flag to disable notifications.
DRemove notify method from user objects.
Step-by-Step Solution
Solution:
  1. Step 1: Identify problem with disabled notifications

    Users who don't want notifications cause null or conditional checks.
  2. Step 2: Apply Null Object pattern

    Provide a NullNotifier that safely ignores notify calls, removing need for checks.
  3. Final Answer:

    Provide a NullNotifier that implements notify but does nothing, avoiding null checks. -> Option A
  4. Quick Check:

    Null Object avoids conditional logic [OK]
Quick Trick: Null Object handles optional behavior safely [OK]
Common Mistakes:
MISTAKES
  • Using exceptions for control flow
  • Relying on global flags
  • Removing required methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes