Single Responsibility
On This Lesson 4 topics
The content for this lesson is written and waiting for review. The outline below shows what it covers. It will be published once it is approved.
In this lesson
give each class one reason to change.
Planned topics
- SOLID is five design guidelines for classes. Guidelines, not laws.
- S: a class should have one reason to change.
- "One responsibility" does not mean "one method".
- Smell: a class that changes for tax rules, for email text, and for database changes.
- Fix: extract classes, each with one clear job.
Draft outline details
Demonstration
class OrderService {
void place(Order o) { /* calculate tax, save, send email */ }
}
// split: TaxCalculator, OrderRepository, OrderNotifierCheck your understanding
Does SRP mean one method per class?
Show answer
No; it means one reason to change.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.