This note is from 2 months ago. You're viewing content from a previous lesson.
You will learn about object oriented programming
You will have a quiz on this when I get back:
Think of it like building Lego: each brick serves a specific role, and combining them creates complex structures. Similarly, SRP encourages building your program from well-defined, specialized units that can be combined to achieve larger goals.
Benefits of SRP:
Examples:
Student class that handles registration, calculates grades, and sends notifications. This violates SRP because it has multiple reasons to change (e.g., registration process update, grading algorithm change, email format change).StudentRegistration class handles enrollment logic.GradeCalculator class calculates and stores grades.NotificationService sends notifications based on events (e.g., registration, grade updates).Each unit in the "good SRP" example has a clear responsibility, making it easier to maintain and adapt changes without affecting other parts of the code.
Remember: SRP isn't about minimizing functionalities within a unit. It's about ensuring each unit has a focused purpose, even if it involves several related functionalities.
By adhering to SRP, you can build cleaner, more manageable, and ultimately more sustainable code in your OOP projects.