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.
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.
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.
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.
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.
SOLID principles are not something you can measure. There isn't something like saying "My code is 100% SOLID".
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 😋