Why does SRP matter?
Why are we concerned with making sure a class only has one responsibility? Having more than
one responsibility makes those responsibilities coupled, even if they are not related. This can
make it harder to refactor the class without unintentionally breaking something else, whereas
having a separate class for each responsibility shields the rest of the code from most of the risk.
It’s also much easier to test a class with only one responsibility: there’s only one thing to test,
although with a potential for many different outcomes, and there’s much less code involved in
that test.
Generally, the smaller the class, the easier it is to test, the easier it is to refactor, and the less
likely it is to be prone to defects.
Do'stlaringiz bilan baham: |