Do you know the common Design Principles? (Part 1)
30/07/2019 10:07 AM by
Figure: Your code should be using
SRP The Single Responsibility Principle
A class should have one, and only one reason to change.
OCP The Open Closed Principle
You should be able to extend a class's behavior without modifying it.
LSP The Liskov Substitution Principle
Derived classes must be substitutable for their base classes.
ISP The Interface Segregation Principle
Make fine-grained interfaces that are client specific.
DIP The Dependency Inversion Principle
Depend on abstractions, not on concretions.
It is assumed knowledge that you know all 5 SOLID principles. If you don't, read about them on Uncle Bob's site above, or watch the SOLID Pluralsight videos by Steve Smith.
- Look for Single Responsibility Principle violations. These are the most common and are the source of many other issues. Reducing the size and complexity of your classes and methods will often resolve other problems.
- Liskov Substitution and Dependency Inversion are the next most common violations, so keep an eye out for them next.
- When teams first begin implementing Dependency Injection, it is common for them to generate bloated interfaces that violate the Interface Segregation Principle.
After you have identified and corrected the most obvious broad principle violations, you can start drilling into the code and looking for localized code breaches. ReSharper from JetBrains or JustCode from Telerik are invaluable tools once you get to this level.
Once you understand common design principles, look at common design patterns to help you follow them in your projects.
Do you feel this rule needs an update?