In software engineering, SOLID is a mnemonic acronym for five design principles intended to make object-oriented designs more understandable, flexible, and maintainable.
—Wikipedia
You heard this before. In fact, most engineers that go into tech and get some formal training get recommended to learn SOLID.
I stopped recommending it.
I’m still somewhat on the fence with dependency inversion and open-closed. But the rest are missing the point.
Ever had this happen?
You read an article on SOLID
You focus on applying all
It’s harder than you thought
You skip LSP
Nope, now it’s silly — you follow LSP and skip OCP instead.
The code is now worse for some reason
Observing engineers SOLID is great for small tactical purely OO problems, but falls short on larger systems design and integration across boundaries. Notably, it was written with Java and C#-compatible languages in mind so it certainly loses appeal with the other language communities. Especially in languages that have pseudo-OO components like PHP and Javascript (non-TS and pre-ecma2023) because object instances cannot be sealed properly.
Engineers love rules
We love rules.
OCP! LSP! Do the curlies go on the same line or new line? It’s religious. It’s addictive.
But SOLID comes with a caveat that everyone misses:
[...]ended to make object-oriented designs more understa[…]
Not all your code is object oriented. Sure, you might say “But Denis, I’m using an object-oriented language!” That’s true. In fact, nowadays most languages on the web are. But I’d wager you’re following a very imperative—do this then do that— way of coding.
You don’t need SOLID to navigate that. You cannot navigate that with just SOLID. That requires a clear understanding of how data and behavior lives and belongs together. And you know which two methodologies express and capture that? DDD and Event Modeling. To not spam you with old articles, here’s the fresh ones that cover them.
Ok, ok— hold on! So why is it being recommended?
Now that’s a great question! This is exactly what got the ball rolling for me to write about this. I’m still refining my thoughts on this so I don’t have a universal answer yet. It will be in my upcoming book.
What I do know is that SOLID principles aren’t a blanket good approach to writing good software— you don’t produce inherently modular, easy to understand and maintainable software by following them.
I’m confident DDD and TDD are much impactful and important for that.
However, the application of SOLID principles is a very good Refactoring method to address code smells in pseudo-object oriented projects.
That’s it— that’s as far as I got for now. I’d love to hear your thoughts on this.