Which of the following design principles suggests that classes should be open for extension, but closed for modification?
- Single Responsibility Principle
- Open/Closed Principle (Correct Answer)
- Liskov Substitution Principle
- Interface Segregation Principle
Explanation
Answer: b) Open/Closed Principle
Explanation:
The Open/Closed Principle suggests that classes should be open for extension, but closed for modification. This means that the behavior of a class can be extended by adding new code, but the existing code should not be modified. The other design principles listed are also important, but they do not directly relate to this concept. The Single Responsibility Principle suggests that a class should only have one reason to change, the Liskov Substitution Principle suggests that subclasses should be able to be used in place of their parent classes without affecting the correctness of the program, and the Interface Segregation Principle suggests that interfaces should be small and focused on a single task.