r/javascript • u/[deleted] • Jan 20 '20
SOLID: Interface Segregation Principle in JavaScript and TypeScript
https://medium.com/@carsten.behrens1/solid-interface-segregation-principle-in-javascript-and-typescript-e5a962e73aee5
u/jkmonger Jan 20 '20
No worries if you don’t know what an interface is, I’ll explain it below.
If someone doesn't know what an interface is when reading an article called "Interface Segregation Principle", don't then spend the majority of the article explaining what an interface is. Direct them elsewhere, and keep your article concise.
1
u/placek3000 Jan 21 '20
This article reminds me a banner where first letters are big and nicely written but the far you go they become more and more narrow to fit in the space that is left. And the end the author throws a sentence in you and gives no explanation or examples.
Personally I like to think about ISP in JS as a rule that encourages you to pass into functions only the data and methods that are needed by that functions. For example you shouldn't pass the whole `cat` object but only the `cat.body` field if all you want is to draw that animal on screen. The draw method doesn't need to know about the `cat.meow()` method or the `cat.name` field so there is no point in coupling the drawing function with those information and potentially encouraging people to use them making the whole code harder to refactor.
8
u/onbehalfofthatdude Jan 20 '20
Man, I did not care for this article one bit. Only one code example that did not illustrate the main point but rather the definition of an interface. The entire support for the thesis is crammed into a couple sentences at the end.