Does the Single Responsibility Principle work in OOP?

前端 未结 7 1089
面向向阳花
面向向阳花 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

    Before you go into decomposing responsibilities, you should have an idea on what the class is supposed to do. It's supposed to do that thing and only that thing as Matt mentioned in his answer. Implement that idea in the simplest way possible just to make it work. That's when you go about decomposing the code you wrote into responsibilities.

    The important thing to consider when you break down your code is to make sure that it is readable after breaking it down.

提交回复
热议问题