Bird
Raised Fist0

Which design best fits this requirement?

hard📝 Trade-off Q15 of Q15
LLD - Behavioral Design Patterns — Part 1
You are designing a logging system using the Chain of Responsibility pattern. You want to handle logs of different severity: DEBUG, INFO, WARNING, ERROR. Each handler should process logs at its level and pass higher severity logs down the chain. Which design best fits this requirement?
AEach handler processes only its level and passes all logs to the next handler
BEach handler processes logs at its level and passes only higher severity logs to the next handler
CEach handler processes all logs regardless of severity and stops the chain
DEach handler processes logs randomly without order
Step-by-Step Solution
Solution:
  1. Step 1: Understand the logging severity flow

    Logs should be handled at their level, and higher severity logs should continue down the chain for further handling.
  2. Step 2: Evaluate options for correct chain behavior

    Each handler processes logs at its level and passes only higher severity logs to the next handler matches this: handlers process their level and pass higher severity logs onward. Each handler processes only its level and passes all logs to the next handler passes all logs regardless, which is inefficient. Each handler processes all logs regardless of severity and stops the chain stops chain prematurely. Each handler processes logs randomly without order is random and incorrect.
  3. Final Answer:

    Each handler processes logs at its level and passes only higher severity logs to the next handler -> Option B
  4. Quick Check:

    Process level, pass higher severity [OK]
Quick Trick: Process own level, pass higher severity logs down [OK]
Common Mistakes:
MISTAKES
  • Passing all logs without filtering
  • Stopping chain too early
  • Ignoring severity order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes