SOLID – Object Oriented Design principles

We usually write code that is-

  • Rigid – Difficult to add new features
  • Fragile – Unable to identify the impact of the change
  • Immobile – No reusability
  • Viscous – Going with the flow of bad practices already being present in the code.

There have been lot of principles for writing good code and all these principles define how the code manages the dependency. Most of them are aware of the principles:

  • Loosely coupled code – There shouldn’t be too much of dependency between the modules, even if there is a dependency it should be via the interfaces and should be minimal.
  • Highly cohesive code- The code has to be very specific in its operations.
  • Context independent code- So that it can be reused.
  • DRY – Dont repeat yourself – Avoid copy-paste of code. Change in the code would have to be made in all the places where its been copied.

Robert C Martin took the initiative and gathered different design principles into a common acronym- SOLID Design principles (The Principles of OOD).

SOLID stands for:

Single Responsibility principle (SRP)
Open Closed principle (OCP)
Liskov Substitution Principle (LSP)
Interface Segregation principle (ISP)
Dependency Inversion principle (DIP)

In subsequent posts I would be writing about the individual principles. The following presentation was prepared by me for a talk on SOLID principles:

%d bloggers like this: