C# object-oriented design principles (four) single responsibility principle

Definition of the single responsibility principle:

1. A class should have one and only one reason for its change, otherwise the class should be split
2. The principle proposes that objects should not take on too many responsibilities, if an object takes on too many responsibilities, when the client needs it When a responsibility of the object, other unnecessary responsibilities have to be included, resulting in redundant code

Advantages of the single responsibility principle:

1. Reduce the complexity of the class, a class is only responsible for one responsibility
2. Improve the readability of the class, reduce the complexity, and increase the natural readability
3. Improve the maintainability of the system
4. Reduce the risk caused by changes

The realization of the single responsibility principle:

1. The designer needs to discover the different responsibilities of the class and separate them, and then encapsulate them into different classes or modules

Guess you like

Origin blog.csdn.net/MrLsss/article/details/109248605