Single Responsibility Principle (SRP) means a class should have only one well-defined responsibility.
For example, if you’re writing a ShoppingCartController, its job is to manage items in the cart: adding, removing, updating quantities, and calculating the total price.
Handling the shipping address? That’s an AddressController.
Processing payments? That’s a PaymentController.
Some apps send you a notification if you have items pending in the cart. That responsibility belongs to a separate PendingItemController (or another name that fits your app).
The main idea is that each class should do one thing well. If a class takes on multiple responsibilities, it becomes harder to maintain, harder to test, and more fragile to changes.
Yes, these controllers will interact with each toher, but their responsibilities should stay separate.
Exciting stuff 🛐. What is Single Responsibility Principle?
Single Responsibility Principle (SRP) means a class should have only one well-defined responsibility.
For example, if you’re writing a ShoppingCartController, its job is to manage items in the cart: adding, removing, updating quantities, and calculating the total price.
Handling the shipping address? That’s an AddressController.
Processing payments? That’s a PaymentController.
Some apps send you a notification if you have items pending in the cart. That responsibility belongs to a separate PendingItemController (or another name that fits your app).
The main idea is that each class should do one thing well. If a class takes on multiple responsibilities, it becomes harder to maintain, harder to test, and more fragile to changes.
Yes, these controllers will interact with each toher, but their responsibilities should stay separate.
Thank you!