Introduction to SOLID Principles

The code is the main source of truth of what developers are really made of. Writing clean and maintainable code is something everybody should aim for. Personally, I’ve been on both ends: being the one who writes smelly code and being the one who refact…


This content originally appeared on DEV Community and was authored by Josué Rodríguez

The code is the main source of truth of what developers are really made of. Writing clean and maintainable code is something everybody should aim for. Personally, I've been on both ends: being the one who writes smelly code and being the one who refactors smelly code. Along the way, I've learned many principles that have really improved my code. A set of those principles are the SOLID Principles.

What is SOLID?

SOLID is an acronym for five software development principles stated by Robert C. Martin, also known as Uncle Bob, for object-oriented programming. Applying these principles will make your code become easier to scale and maintain. It will also make your project development more productive through decomposition and decoupling by removing code smells and reducing time spent on refactoring.

The acronym stands for:

  • S - Single-responsibility Principle
  • O - Open-closed Principle
  • L - Liskov Substitution Principle
  • I - Interface Segregation Principle
  • D - Dependency Inversion Principle

SOLID tends to improve code rigidity, fragility, reusability, and remove needless complexity.

Common misconceptions about SOLID

Is SOLID made for programming languages, frameworks, or what?

SOLID is neither a framework, nor a library, nor a pattern. It is also not bound to any particular technology. You can apply these principles to your favorite programming language such as TypeScript or Java, or to your favorite framework such as React or Express.

Is there an order to apply the principles?

Not really. They have only been arranged this way to spell SOLID and make it catchy. I read once that the acronym came to life because a friend of Robert C. Martin told him that if he swapped the order of the letters, they would spell SOLID.

Do I have to apply the 5 principles to my project?

The number of principles you will apply to your project will depend on the smells your code has. Each principle addresses a specific problem, and if your code does not have that problem, there's no reason to apply the principle.

How SOLID is my code?

SOLID principles are not something you can measure. There isn't something like saying "My code is 100% SOLID".

Closing words

I'll create a series explaining every SOLID principle. The explanation will be beginner-friendly and with code examples. I'm always open to suggestions and comments since I'm still a newbie at writing blogs ?


This content originally appeared on DEV Community and was authored by Josué Rodríguez


Print Share Comment Cite Upload Translate Updates
APA

Josué Rodríguez | Sciencx (2021-04-13T23:41:07+00:00) Introduction to SOLID Principles. Retrieved from https://www.scien.cx/2021/04/13/introduction-to-solid-principles/

MLA
" » Introduction to SOLID Principles." Josué Rodríguez | Sciencx - Tuesday April 13, 2021, https://www.scien.cx/2021/04/13/introduction-to-solid-principles/
HARVARD
Josué Rodríguez | Sciencx Tuesday April 13, 2021 » Introduction to SOLID Principles., viewed ,<https://www.scien.cx/2021/04/13/introduction-to-solid-principles/>
VANCOUVER
Josué Rodríguez | Sciencx - » Introduction to SOLID Principles. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/04/13/introduction-to-solid-principles/
CHICAGO
" » Introduction to SOLID Principles." Josué Rodríguez | Sciencx - Accessed . https://www.scien.cx/2021/04/13/introduction-to-solid-principles/
IEEE
" » Introduction to SOLID Principles." Josué Rodríguez | Sciencx [Online]. Available: https://www.scien.cx/2021/04/13/introduction-to-solid-principles/. [Accessed: ]
rf:citation
» Introduction to SOLID Principles | Josué Rodríguez | Sciencx | https://www.scien.cx/2021/04/13/introduction-to-solid-principles/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.