Rules

Secret ingredients to quality software

Edit
Info

Do you know the common Design Principles? (Part 1)

Last updated by Christian Morford-Waite on 26 Feb 2021 05:05 am (4 months ago) See History

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.

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.

What order?

  1. 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.
  2. Liskov Substitution and Dependency Inversion are the next most common violations, so keep an eye out for them next
  3. 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.

Adam StephensenAdam Stephensen
Damian BradyDamian Brady

We open source. This page is on GitHub