Common principle of responsibility: class level or method level

I have a problem in understanding the principle of shared responsibility. If SRP is applied at the class level or at the method level. Suppose I have a Student Class, I need to create a student, update the student, and remove the student. If I create a service class that has methods for these three actions, this will violate the SRP principle.

+9
source share
3 answers

I would say that you have a service class that is responsible for CRUD operations on type objects Student. I do not see this project violating SRP.
Quote from http://www.developerfusion.com/article/137636/taking-the-single-responsibility-principle-seriously/

Two methods of the same class (or even different classes) should focus on different aspects. However, two methods in one class, for example. repository, probably both should be associated with the same responsibility of a higher level, for example. perseverance.

CRUD , . , - . , SOLID .
, . , (, ), , .

+4

SRP , . , , , , CRUD . , , InsertStudent , . SRP. InsertStudent, UpdateStudent, , SRP

+4

, , , , , "". , , "". - - , . , , , .

, . , , "" . , . .

, . , . , , , .

- SOLID , , , , . . , , .

, . , Ecto, , "Voilร ", . , Ecto , , , . , .

, , , , , , . , , - .., . , , . .

, , . , Mail , css "" - "# FF0000". , , , , "", .

It is not easy. In your particular case, I personally would not mix, for example, โ€œcreateโ€ and โ€œdeleteโ€, but I would make sure that interacting with the database is all that he does. He does not know if the thing is valid, whether it has callbacks, etc. Pretty much the Repository pattern. Again, Ecto is a good example, or at least I find it useful.

0
source

Source: https://habr.com/ru/post/1617814/


All Articles