0

In the System.Data.Entity namespace there's the DbFunctions class. It has nearly 100 functions that handle string manipulation, DateTime calculations, and statistical functions. There are a lot of SRP questions on SO, so feel this is the appropriate forum. Wikipedia defines SRP as follows:

The single responsibility principle states that every module or class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility

It seems to me that DbFunctions is a violator.

When defining what a class's purpose is many people advocate counting the number of "ands" you use in the definition. More than one and you may be in violation of the SRP. By my count, there are at least 3 in DbFunctions. Is my understanding of SRP flawed or too literal? I know there are always edge-cases, but this, in my mind, seems like it violates SRP. This certainly doesn't diminish the ultra-usefulness of the class.

Does this class conform to SRP?

Big Daddy
  • 5,160
  • 5
  • 46
  • 76
  • Downvote? Please...there's nothing wrong with this question. I've put a lot of thought and research into the subject and am looking for meaningful responses. – Big Daddy Feb 19 '16 at 20:10
  • The question does indeed show a good amount of thought and research, but you posted it on the wrong site. SO is not for specific programming questions, which this is not. – Mad Physicist Feb 22 '16 at 14:38
  • 1
    @MadPhysicist...I had mixed emotions on where to post. There are a lot of opinion-based SRP questions on SO - that's why I chose to post here. Really, most everything SOLID related is opinion-based and there are a lot of SO postings on the subject. If the SO admins don't agree with me, can someone migrate to the appropriate forum? – Big Daddy Feb 22 '16 at 15:02

1 Answers1

1

I do not think it violates SRP. Below is definition given in MSDN which

Provides common language runtime (CLR) methods that expose EDM canonical functions for use in DbContext or ObjectContext LINQ to Entities queries.

Responsibility in above definition is to expose EDM Canonical functions to use in Linq To SQL queries which is single responsibility.

Matthew Whited
  • 22,160
  • 4
  • 52
  • 69
Viru
  • 2,228
  • 2
  • 17
  • 28
  • 1
    How about the all to familiar "Manager" class that exposes "related" functions? Related sure, SRP, usually not. – Big Daddy Feb 19 '16 at 19:30
  • Why do you think `SOLID` is a magical bullet and all software should be built with 100% compliance? Ignoring that just cause you don't see a relationship doesn't mean it doesn't exist. – Matthew Whited Feb 19 '16 at 19:33
  • 1
    @MatthewWhited...I didn't say anything about 100% compliance or SOLID is a magic bullet. I'm just questioning my understanding, and others too I think, of SRP. – Big Daddy Feb 19 '16 at 19:41
  • @BigDaddy As far as I understand SRP is class sizing principle...Meaning class should have only one reason to change...that what single responsiblity means here...So ask yourself when this class will change? Dont think that Date and Math functions to be seperate....Maybe developers who implemented it know that this methods might be impacted by single change\reason.. – Viru Feb 19 '16 at 19:45