LLD - Behavioral Design Patterns — Part 2Which of the following is the correct way to implement a Null Object in a class hierarchy?ACreate a subclass that overrides methods with empty implementationsBUse a global variable set to nullCThrow exceptions in the Null Object methodsDReturn null from all methods in the Null ObjectCheck Answer
Step-by-Step SolutionSolution:Step 1: Identify how Null Object should behaveIt should implement the same interface but provide harmless (empty) behavior.Step 2: Choose the correct implementation approachCreating a subclass that overrides methods with empty implementations fits the pattern.Final Answer:Create a subclass that overrides methods with empty implementations -> Option AQuick Check:Null Object subclass overrides methods safely [OK]Quick Trick: Null Object overrides methods with empty bodies [OK]Common Mistakes:MISTAKESUsing null variables instead of objectsThrowing exceptions defeats Null Object purposeReturning null causes errors again
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 - Command pattern - Quiz 12easy Behavioral Design Patterns — Part 1 - Chain of Responsibility pattern - Quiz 11easy Behavioral Design Patterns — Part 1 - Command pattern - Quiz 4medium Behavioral Design Patterns — Part 2 - Why more behavioral patterns solve communication - Quiz 14medium Design — Elevator System - Elevator, Floor, Request classes - Quiz 11easy Design — Library Management System - Reservation and hold system - Quiz 4medium Design — Library Management System - Class design (Book, Member, Librarian, Loan) - Quiz 2easy Design — Library Management System - Reservation and hold system - Quiz 2easy Design — Parking Lot System - Parking strategy pattern - Quiz 5medium Design — Parking Lot System - Enum usage (VehicleType, SpotType) - Quiz 13medium