SOLID Design Principles and Other Patterns Revisited For .NET
“I want to document stuff I learn or problems that I come across in my job, for myself and others”, Andras Nemes, a Swedish web developer on the .NET platform, writes when explaining why he is doing a series of blog posts on the SOLID design principles and other design patterns he has found interesting in object-oriented programming and design.
Andras describes the SOLID design principles as a collection of guidelines for object oriented software design where each of them are meant to make a code base easier to understand and maintain. They also encourage a more object oriented style, thus preventing the code base from becoming a mess with a large degree of interdependency that is hard to debug and extend.
But he also states that even though the principles are a good set of tools they do not replace the need for maintaining and refactoring your code to keep it from getting stale.
The five design principles the SOLID acronym stands for are, using Andras' brief description:
- Single Responsibility Principle states that every object should only have one reason to change, i.e. every object should perform one thing only.
- Open-Closed Principle states that classes should be open for extension and closed for modification.
- Liskov Substitution Principle states that you should be able to use a derived class in place of a parent class and it must behave in the same manner.
- Interface Segregation Principle states that clients should not be forced to depend on interfaces they do not use.
- Dependency Inversion Principle helps to decouple your code by ensuring that you depend on abstractions rather than concrete implementations.
For each of the principles Andras describes the pattern together with when and where you should use it. He then uses the pattern in a demo where he first implements an example not using the pattern, followed by a refactoring to improve the code by adapting to the pattern. He also argues about what is the problem with the first design and in what way the design improves with the refactoring.
Besides the SOLID principles Andras has in the same style described several other patterns including: Command, Builder, Visitor, Bridge and Observer.
Camille Fournier May 21, 2015