LLD - Advanced LLD ConceptsIf a class in the LLD violates the 'open-closed principle', what is the MOST appropriate corrective measure?ARefactor the class to allow behavior extension via inheritance or composition without modifying existing codeBMerge the class with other classes to reduce the number of modulesCRemove all public methods to prevent external changesDRewrite the entire class from scratch using a different programming languageCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand open-closed principleIt states software entities should be open for extension but closed for modification.Step 2: Identify fixRefactoring to support extension via inheritance or composition achieves this without modifying existing code.Step 3: Eliminate incorrect optionsMerging classes or removing public methods does not address the principle; rewriting is unnecessary.Final Answer:Refactor the class to allow behavior extension via inheritance or composition without modifying existing code -> Option AQuick Check:Enable extension without changing existing code [OK]Quick Trick: Refactor for extension without modification [OK]Common Mistakes:MISTAKESThinking rewriting is the only solutionConfusing open-closed with encapsulation
Master "Advanced LLD Concepts" in LLD9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepArchTryChallengeDesignRecallScale
More LLD Quizzes Advanced LLD Concepts - Anti-patterns to avoid - Quiz 9hard Design โ Food Delivery System - Restaurant, Menu, Order classes - Quiz 3easy Design โ Food Delivery System - Restaurant, Menu, Order classes - Quiz 10hard Design โ Food Delivery System - Delivery agent assignment - Quiz 13medium Design โ Food Delivery System - Notification to all parties - Quiz 4medium Design โ Food Delivery System - Restaurant, Menu, Order classes - Quiz 4medium Design โ Hotel Booking System - Hotel, Room, Booking classes - Quiz 4medium Design โ Online Shopping Cart - Product, Cart, Order classes - Quiz 2easy Design โ Online Shopping Cart - Notification on state change - Quiz 5medium Design โ Splitwise (Expense Sharing) - Why Splitwise tests financial logic - Quiz 13medium