Which of the following best describes the Single Responsibility Principle in object-oriented design?
Think about how many reasons a class should have to change.
The Single Responsibility Principle states that a class should have only one reason to change, meaning it should focus on a single responsibility or job. This keeps classes simple and easier to maintain.
You have a payment processing system that needs to support new payment methods without modifying existing code. Which design approach aligns best with the Open/Closed Principle?
Consider how to add new features without changing existing code.
The Open/Closed Principle states that software entities should be open for extension but closed for modification. Creating new classes that inherit from a common interface allows adding new payment methods without changing existing code.
In a large system, you have a base class Vehicle and subclasses like Car and ElectricCar. Which design choice violates the Liskov Substitution Principle?
Think about substituting subclasses without breaking the program.
The Liskov Substitution Principle requires that subclasses can replace their base classes without affecting correctness. Throwing exceptions in overridden methods breaks this rule.
Which scenario best illustrates a violation of the Interface Segregation Principle?
Consider how clients should depend on interfaces.
The Interface Segregation Principle states that clients should not be forced to depend on interfaces they do not use. Large interfaces with unused methods violate this principle.
In a layered system, high-level modules directly depend on low-level modules instead of abstractions. What is the most likely impact of this design choice?
Think about coupling and flexibility between layers.
The Dependency Inversion Principle encourages depending on abstractions, not concrete implementations. Direct dependency on low-level modules causes tight coupling and reduces flexibility.