Which of the following best describes the Single Responsibility Principle (SRP) in class 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 behavior.
In a library management system, which class should be responsible for checking out a book to a user?
Consider which class should handle the process involving multiple entities.
The CheckoutManager class is responsible for coordinating the checkout process, involving both the User and the Book, keeping responsibilities clear and separated.
As a messaging app grows, which approach best helps to keep class responsibilities manageable and scalable?
Think about how to keep classes focused and easy to maintain as the system grows.
Dividing responsibilities into specialized classes helps maintain clear boundaries, making the system easier to scale and maintain.
What is a potential downside of making classes too fine-grained with very narrow responsibilities?
Consider what happens when there are many small classes in a system.
While fine-grained classes improve focus, having too many can make the system harder to understand and maintain due to increased complexity.
In a ride-sharing system, which class should be responsible for calculating the fare of a ride?
Think about separating calculation logic from data representation.
The FareCalculator class centralizes fare computation logic, keeping pricing rules separate from data classes like Ride or User.