DEV Community

loading...
Cover image for Introduction to SOLID Principles

Introduction to SOLID Principles

Josué Rodríguez (He/Him)
A Honduran systems engineer trying to improve himself everyday.
・2 min read

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 😋

Discussion (0)