nus-cs2113-AY2324S1 / forum

0 stars 0 forks source link

Does SRP require single responsibility of methods? #41

Closed skylee03 closed 1 year ago

skylee03 commented 1 year ago

For the question:

As per SRP, a method should have only one responsibility. (Week 9 Quiz Part II Q16)

The standard answer is:

False. The SRP is about classes, not methods.

However, in our supplementary reading, the author reasoned about SRP and came to the following conclusion:

(To ensure that SRP is respected,) when we design our software we should:

  1. Find and define the actors.
  2. Identify the responsibilities that serve those actors.
  3. Group our functions and classes so that each has only one allocated responsibility.

The author seems to believe that the single responsibility of functions (i.e., methods) is one of the necessary conditions to ensure SRP is followed. I am wondering that, in other words, does SRP require single responsibility for methods?

okkhoy commented 1 year ago

I don't understand the numbered list that way.

If you read the earlier part of the article, it talks about a family of functions in the context of serving the role and changing to serve the role. So I understand it as group functions (to a class) such that each class has a responsibility.

However, your question is valid. Here is a reasonable explanation: https://stackoverflow.com/questions/56893910/what-is-the-scope-of-the-single-responsibility-principle/57085753#57085753