LLD - Behavioral Design Patterns — Part 1Why does the Strategy pattern promote the Open/Closed Principle in software design?ABecause it forces all algorithms to be written in one class.BBecause new strategies can be added without modifying existing code.CBecause it prevents any changes to the Context class.DBecause it removes the need for interfaces.Check Answer
Step-by-Step SolutionSolution:Step 1: Recall Open/Closed PrincipleSoftware entities should be open for extension but closed for modification.Step 2: Relate to Strategy patternStrategy pattern allows adding new algorithms (strategies) by creating new classes without changing existing code.Final Answer:Because new strategies can be added without modifying existing code. -> Option BQuick Check:Strategy supports Open/Closed by extension without modification [OK]Quick Trick: Add new strategies without changing old code [OK]Common Mistakes:MISTAKESThinking all algorithms in one classBelieving Context cannot changeAssuming interfaces are removed
Master "Behavioral Design Patterns — Part 1" in LLD9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepArchTryChallengeDesignRecallScale
More LLD Quizzes Behavioral Design Patterns — Part 1 - Template Method pattern - Quiz 1easy Behavioral Design Patterns — Part 2 - Memento pattern - Quiz 1easy Behavioral Design Patterns — Part 2 - Visitor pattern - Quiz 4medium Design — Elevator System - Why elevator design tests state machines - Quiz 6medium Design — Library Management System - Notification system - Quiz 14medium Design — Library Management System - Fine calculation - Quiz 12easy Design — Parking Lot System - Why parking lot is a classic LLD problem - Quiz 1easy Design — Tic-Tac-Toe Game - Command pattern for undo - Quiz 13medium Design — Tic-Tac-Toe Game - Extensibility (NxN board, multiple players) - Quiz 8hard Design — Tic-Tac-Toe Game - Command pattern for undo - Quiz 1easy