Does the Single Responsibility Principle work in OOP?

前端 未结 7 1072
面向向阳花
面向向阳花 2020-12-03 15:17

I am struggling to understand how the Single Responsibility Principle can me made to work with OOP.

If we are to follow the principle to a tee, then are we not left

7条回答
  •  天命终不由人
    2020-12-03 16:10

    I quote Robert C. Martin from his book Clean Code:

    The Single Responsibility Principle (SRP) states that a class or module should have one, and only one, reason to change. This principle gives us both a definition of responsibility, and a guidelines for class size. Classes should have one responsibility—one reason to change.

提交回复
热议问题