SOLID is a mnemonic acronym for five design principles intended to make object-oriented designs more understandable, flexible, and maintainable.

The principles are a subset of many principles first introduced by Robert C. Martin in 2000th in the paper Design Principles and Design Patterns

  • Single Responsibility Principle. srp.pdf

    “There should never be more than one reason for a class to change.”

  • Open-Closed Principle.

    Original ocp

    Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.

    Update 2014

    You should be able to extend the behavior of a system without having to modify that system.

  • Liskov Substitution Principle. lcp

    Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it.

  • Interface Segregation Principle. isp

    Clients should not be forced to depend upon interfaces that they do not use.

  • Dependency Inversion Principle. dip

    Depend upon abstractions, [not] concretions.”

C# notes

Single Responsibility Principle

A class should have only one responsibility, do only one thing. For ex. convert text to html, but not convert text to html and upload it to the storage.

Open-Closed Principle

After introducing a new feature if code in present class, function, etc is changing somehow this principle is violated. Create plugin system.

Liskov Substitution Principle.

The new modifier should not be used to override virtual methods in inherited classes.

Interface Segregation Principle.

If two classes need to use different methods from one interface, the interface should be split into two.

Dependency Inversion Principle.

Pass interfaces as parameters instead of classes.