
Testing in Node.js by example using the SOLID principles - christian_fei
https://cri.dev/posts/2020-05-20-Testing-in-Nodejs-by-example-using-the-SOLID-principles/
======
compressedgas
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.

~~~
christian_fei
makes sense, thanks for the reply and clarification.

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...](https://blog.cleancoder.com/uncle-
bob/2014/05/08/SingleReponsibilityPrinciple.html)

~~~
compressedgas
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.

~~~
adamkl
I think you are confusing SRP (Single Responsibility Principal [0]) with ISP
(Interface Segregation Principal [1]).

[0] [https://en.m.wikipedia.org/wiki/Single-
responsibility_princi...](https://en.m.wikipedia.org/wiki/Single-
responsibility_principle)

[1]
[https://en.m.wikipedia.org/wiki/Interface_segregation_princi...](https://en.m.wikipedia.org/wiki/Interface_segregation_principle)

~~~
compressedgas
I think I did. They are so similar that I have mentally merged them as they
are a symmetric pair. One is dual to the other.

