Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing JavaScript according to SOLID

Have any one used the SOLID programming principle (or any of it's parts) while developing JavaScript?

I've just started up on reading on it but can't seem to find anyone that used it for JS. The only part I find easy to implement/use is the "Single responsibility principle".

What I'm looking for is articles or example where these principles are used. And are there any argument's why one shouldn't use some parts?

For example the "Interface segregation principle" says that "the notion that many client specific interfaces are better than one general purpose interface."

But from my knowledge there's no such thing as interfaces in JS (nice if it would be).

like image 981
fredrik Avatar asked Jan 17 '11 09:01

fredrik


People also ask

Do SOLID principles apply to JavaScript?

The single responsibility principle is one of five object-oriented design (OOD) guidelines that comprise the SOLID design principles.

What is SOLID in JS?

SOLID stands for. S: Single Responsibility Principle. O: Open-Closed Principle. L: Liskov-Substitution Principle. I: Interface Segregation Principle.

Does SOLID apply to functional programming?

Are the SOLID principles applicable to Functional Programming? Of course. Functional programmers want to separate their code to avoid crosstalk between responsibilities and users. They want to minimize the number of modules affected by a change.


2 Answers

It looks like Derek Greer is attempting to take a stab at this with his article series on SOLID JavaScript at Fresh Brewed Code:

  1. The Single Responsibility Principle
  2. The Open/Closed Principle
  3. The Liskov Substitution Principle
  4. The Interface Segregation Principle
  5. The Dependency Inversion Principle
like image 144
Ryan Ransford Avatar answered Sep 26 '22 00:09

Ryan Ransford


JavaScript sometimes gets a bad rap as being sub-par to those such as C++, C#, and Java, when in fact it's a very powerful functional programming language that also has object oriented capabilities (although it's not really classified as object oriented)

Perhaps many developers look down on it because so many of them are used to seeing poor programming practices and consequently, buggy behavior in JavaScript. For some unknown reason, it seems more acceptable to be sloppy on the client side. This is something I would like to change.

I believe these SOLID principles are solid. (No pun intended). If you follow these conventions, you will be less likely to accumulate technical debt created by sloppy code, shortcuts, and no architecture. Your code will be more maintainable, more reusable, more modular, less tightly coupled, and scalable and extensible. You'll also be contributing to demonstrating the full power of JavaScript when your product is engineered instead of just recklessly slapped together.

This document describes the fundamentals of SOLID. The same rules apply whether you're referring to C++, Java, JavaScript, or any other object-oriented language.

Code Project - The SOLID Object Oriented Programming Principles

Here is some more information on JavaScript concepts on colourcoding.net.

like image 14
jmort253 Avatar answered Sep 26 '22 00:09

jmort253