How should you organize the chain to ensure that a log message is handled by the appropriate handler and not by others?
hard📝 Trade-off Q8 of 15
LLD - Behavioral Design Patterns — Part 1
You need to design a logging system using the Chain of Responsibility pattern where different handlers process logs of different severity levels (INFO, WARNING, ERROR). How should you organize the chain to ensure that a log message is handled by the appropriate handler and not by others?
AArrange handlers randomly and let each handler process all messages regardless of severity.
BArrange handlers in order from highest to lowest severity, each handler processes only its level and passes others down the chain.
CUse a single handler that processes all severity levels without chaining.
DArrange handlers in order from lowest to highest severity, each handler processes all messages.
Step-by-Step Solution
Solution:
Step 1: Understand severity-based handling
Handlers should process messages matching their severity and pass others down the chain.
Step 2: Determine chain order
Ordering from highest to lowest severity ensures critical messages are handled first, others passed down.
Final Answer:
Arrange handlers in order from highest to lowest severity, each handler processes only its level and passes others down the chain. -> Option B
Quick Check:
Severity order chain ensures correct handler processes message [OK]
Quick Trick:Order handlers by severity descending for proper processing [OK]
Common Mistakes:
MISTAKES
Random handler order causing wrong processing
All handlers processing all messages
Using single handler without chain
Master "Behavioral Design Patterns — Part 1" in LLD
9 interactive learning modes - each teaches the same concept differently