Search code examples
oopsolid-principlessingle-responsibility-principle

Single Responsibility Principle(SRP) and my Service Class


I have YoutubeVideoService class which does CRUD(Create, Read, Update, and Delete) operations. In my view Create, Read, Update, and Delete are four reasons for a class to change. Does this class violates Single Responsibility Principle?

If it violates, then should we have four classes like CreateYoutubeVideoService, ReadYoutubeVideoService, UpdateYoutubeVideoService and DeleteYoutubeVideoService. Isn't it an overkill to have lots of classes?


Solution

  • I think you're taking the Single Reposibility Principle a bit to the extreme on a class level, without taking into consideration cohesion.

    If you follow that route, you could justify having lots of classes with just one or two methods, which in turn would increase the number of dependencies to the sky.

    I think the spirit of SRP is Simplify as much as you can, but not more.