Do you know the common Design Principles? (Part 1)
3/03/2017 6:14 AM by
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 classes behavior without modifying it.
LSP The Liskov Substitution Principle
Derived classes must be substitutable for their base classes.
ISP The Interface Seg regation Principle
Make fine-grained interfaces that are client-specific.
DIP The Dependency Inversion Principle
Depend on abstractions, not on concretions.
Figure: Your code should be using SOLID principles
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?