SOLID design principles in C++: Open Closed Principle
vishalchovatiya.com
vishalchovatiya.com
Designing all classes in your software to be "extensible in the future for new business requirements" is such a useless (and in most cases, harmful) goal. The number of classes and interfaces should be kept to a possible minimum. In fact, the number of lines should be kept to a reasonable minimum. Rewriting code is good. Refactoring classes to be more generalized (when it actually is needed) is good.
These so-called principles are such newbie traps and they go against the only principle in software engineering, the only law of the land that I recognize: your code should be simple and readable.
Which principles you should stick to should be decided by your team, and based on your context: language, app/library, test approach, budget, etc.
They lure the newbie (or worse, beginner experts) with a "learn me and become an expert" bait.
They usually don't stand on a substantial merit. They are hyped up by some famous nerd and it perpetuates because every body hears someone talk about it.
I can literally make up other legitimate sounding principles on the spot that mean nothing.
If you hype it up enough people will start repeating it. Until the little kid notices that the emperor is walking around all naked.
Perhaps it's not the SOLID principles that are bad, but they way you've seen them used? More important than the principles is how they're interpreted and implemented, I think.
- Extensibility: Not true, unless you solve the expression problem either you pay while adding new types, or you pay while adding new functions
- Maintainability: Not true, dressing code in layers of indirection is a recipe for unmaintainable code due to spaghetti control flow
- Flexibility: At one point, you can't shove an accretive development model through the door, it's just too clunky and won't fit.
Also all those patterns that keep being mentioned (Factory ew) just highlight deficiencies in the programming language.
Full disclosure, I’m not a professional C++ developer. I haven’t touched the language in 20 years. However, I’ve attempted to keep up with its development since my hobby game development years in my teens.