Reputation: 192
Recently i'm reading the Clean Architecture by Robert Martin.
I have some misunderstading about couple of SOLID principles definitions. Exactly the Single Responsibility Principle and Open/Closed Principle.
Well for the first one we have the following
A class (module) should have only one reason to change
Where the reason means actor. Sounds pretty clear.
Move on the next one - OCP. Here we have such example
The misunderstood part is the Database and Interactor relation. We implement the Financial Data Gateway
interface in the Database
component by Financial Data Mapper
, so we have two modules with one responsibility. Seems like SRP violation.
Am i right or just missing something for a correct understanding?
Upvotes: 1
Views: 502
Reputation: 7744
I would like to highlight that the listed design approach is neither object-oriented nor a good architecture to have for most if not all situations. Here is an article of mine with more details of why this is the case.
The single responsibility principle has also multiple, sometimes conflicting interpretations. What it should mean in an object-oriented context is basically strong cohesion and loose coupling. Here is a slidedeck of mine explaining all this from a pragmatical standpoint.
So, with due respect, I think you may have the wrong concept of SRP, OCP, the practicality or viability of the "Clean Architecture" and of object-orientation in general.
With all that said, the answer is: the grammar of your question is all wrong. There is no such thing as an "SRP violation". SRP is very loosely defined, and even if you pick an interpretation it is not a binary thing. It is a scale that depends heavily on requirements and context and can not (should not) be evaluated on its own in isolation.
Upvotes: 1