Definition: You should and only have one reason to change the class.
Understand:
If a class takes on too much responsibility, it is tantamount to coupling these responsibilities, and a change in responsibility may weaken or inhibit the ability of this class to perform other duties,
This coupling can lead to fragile designs. When the change occurs, the design suffers unexpected damage.
If a class A, there are two responsibilities, a, a, when responsibility a due to changes in requirements and needs to be modified, it is possible to cause the function of Duty B to fail.
Solve:
Separate the responsibilities in the class, and create two classes respectively.
If it is interface-oriented programming, it is to abstract two responsibilities into two different interfaces, the original interface to implement both interfaces.
Benefits of a single responsibility principle:
1. Reduced complexity of classes
2. Improved readability
3. Improved maintainability
4. Reduced risk due to change
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
6 design Principles (1): Single duty principle