LLD - Behavioral Design Patterns — Part 2Which of the following is a correct way to define a Null Object class in a system design context?Aclass NullLogger { log(message) { throw new Error('Null'); } }Bclass NullLogger { log(message) { console.error(message); } }Cclass NullLogger { log(message) { return null; } }Dclass NullLogger { log(message) { /* do nothing */ } }Check Answer
Step-by-Step SolutionSolution:Step 1: Understand Null Object behaviorIt should implement the interface with safe, do-nothing methods.Step 2: Evaluate optionsclass NullLogger { log(message) { /* do nothing */ } } does nothing safely. class NullLogger { log(message) { throw new Error('Null'); } } throws error, C returns null (not safe), D logs error (not silent).Final Answer:class NullLogger { log(message) { /* do nothing */ } } -> Option DQuick Check:Null Object method = safe no-op [OK]Quick Trick: Null Object methods do nothing safely [OK]Common Mistakes:MISTAKESThrowing errors inside Null ObjectReturning null instead of safe objectLogging errors in Null Object methods
Master "Behavioral Design Patterns — Part 2" in LLD9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepArchTryChallengeDesignRecallScale
More LLD Quizzes Behavioral Design Patterns — Part 1 - Observer pattern - Quiz 12easy Behavioral Design Patterns — Part 1 - Strategy pattern - Quiz 7medium Behavioral Design Patterns — Part 1 - Template Method pattern - Quiz 2easy Design — Elevator System - Emergency handling - Quiz 12easy Design — Elevator System - Elevator, Floor, Request classes - Quiz 8hard Design — Elevator System - Scheduling algorithm (SCAN, LOOK) - Quiz 15hard Design — Library Management System - Search functionality design - Quiz 9hard Design — Parking Lot System - Concurrency considerations - Quiz 13medium Design — Parking Lot System - Class identification (ParkingLot, Floor, Spot, Vehicle) - Quiz 8hard Design — Tic-Tac-Toe Game - Board, Player, Game classes - Quiz 10hard