DEV Community

Discussion on: SOLID Principle in Javacript

Collapse
 
kspeakman profile image
Kasey Speakman • Edited

You have attributed the difficulty in following SOLID principles to Javascript being "functional oriented". However, I believe the difficulty translating the concepts to JS is actually because JS is dynamically typed. In dynamic languages, Liskov and Interface Segregation can be mostly ignored due to "duck typing". (Like all principles I'm sure this is arguable, especially because JS has prototypal inheritance. But just because it's there doesn't mean you have to use it.) Conversely, you need to have tests to verify assumptions about objects, which may (or may not) have otherwise been covered by typing.

Here is a slide deck I found about SOLID principles in Angular, although it is for an older version. It also uses TypeScript, but the only type annotations I saw were on strings, so it is basically still dynamic ES6.

SOLID Principles in Angular

Here is a pretty simple overview of what SOLID principles looks like in Ruby, also a dynamic language.

SOLID Principles in Ruby

Collapse
 
subbramanil profile image
Subbu Lakshmanan

Thank you Kasey!!.

However, I believe the difficulty translating the concepts to JS actually lies in JS being dynamically typed.

I understand your point.

Appreciate for sharing the information!!

Collapse
 
kayis profile image
K

In dynamic languages, Liskov and Interface Segregation can be mostly ignored due to "duck typing"

Also, I have the feeling that the Liskov substitution principle is a rather outdated point. Back in the days inheritance was the thing in OOP, but now most devs try to avoid it and use aggregations anyway.