No. That's not what the SRP means at all. The SRP is specifically about interfaces and how each interface should be responsible to a single client. An object that serves more than one client should implement each of the interfaces required. The original article is quite clear on what the SRP is.
Please don't confuse SOLID and Clean Code.
I don't mind if you want to follow the Clean Code statement of: Each function should do only one thing. But that isn't the SRP.
The interfaces don't have to have representation in the language for their existence. This is true for all programming constructs. They are patterns imposed by design that can exist without support from the language.
A language does not need to have interfaces to have interfaces. An interface is simply a set of methods and the contracts those methods obey. An object can be said to implement an interface if it has the methods that obey the required contracts. Interfaces are entirely about decoupling. Such that the client of an interface depends on the contract of that interface and not any object that implements it.
The SRP in SOLID is about factoring interfaces such that each client ends up with interfaces that are specific to its use of the object rather than depending on an interface that provides more than is needed. That is the interface is responsible to a single client.
The example for SRP that is given is an interface that combines two distinct uses. By splitting those interfaces, the code that results is more flexible even if there is only one object that implements both interfaces.
Neither of those SRP mentioned in that article are the specific SRP that appears in SOLID. Nothing wrong with that. Please cite Clean Code or that article, rather than SOLID, for them.
7 comments
[ 2.9 ms ] story [ 31.4 ms ] threadPlease don't confuse SOLID and Clean Code.
I don't mind if you want to follow the Clean Code statement of: Each function should do only one thing. But that isn't the SRP.
although, how do you suggest to phrase it / to apply SRP in a language without interfaces e.g. Node.js?
In my opinion it's more about coupling than interfaces.
I feel I'm quite in line with the following by unclebob, let me know what you think, i'm open to learn more
https://blog.cleancoder.com/uncle-bob/2014/05/08/SingleRepon...
A language does not need to have interfaces to have interfaces. An interface is simply a set of methods and the contracts those methods obey. An object can be said to implement an interface if it has the methods that obey the required contracts. Interfaces are entirely about decoupling. Such that the client of an interface depends on the contract of that interface and not any object that implements it.
The SRP in SOLID is about factoring interfaces such that each client ends up with interfaces that are specific to its use of the object rather than depending on an interface that provides more than is needed. That is the interface is responsible to a single client.
The example for SRP that is given is an interface that combines two distinct uses. By splitting those interfaces, the code that results is more flexible even if there is only one object that implements both interfaces.
Neither of those SRP mentioned in that article are the specific SRP that appears in SOLID. Nothing wrong with that. Please cite Clean Code or that article, rather than SOLID, for them.
[0] https://en.m.wikipedia.org/wiki/Single-responsibility_princi...
[1] https://en.m.wikipedia.org/wiki/Interface_segregation_princi...