What is a responsibility?
In his description of the Single Responsibility Principle, Robert Martin describes a responsibility
as “a reason for change.” Any time we look at a given class and see more than one way in which
we might change it, then that class has more than one responsibility.
Another way to look at a responsibility is to look at the behavior of a class. If it has more than
one behavior, it is violating SRP.
Let’s look at a class that represents a
User
record stored in a database:
¹³
http://www.objectmentor.com/resources/articles/Principles_and_Patterns.pdf
SOLID Design Principles
32
Do'stlaringiz bilan baham: |