What is the single responsibility principle?

"A class should have one, only one reason to change."

– Robert C. Martin

This means that one class should have only one responsibility. If a class is doing multiple things, this is a violation of the Single Responsibility Principle (SRP). For example, if we have a class named Student, it should only be responsible for student-related data. If the Student class needs to be modified when changing anything in the Teacher class, the Student class is violating the SRP.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.52.33