Open In App

OOD Principles | SOLID

Improve
Improve
Like Article
Like
Save
Share
Report

Object Oriented Programming paradigm deals with centralizing data and associated behaviors in a single entity. The entities will communicate by message passing. High-level languages like C++, Java, C#, etc… provide rich features in designing applications. One can learn the language constructs easily. However, few design principles guide the programmer for better utilization of language features. The following principles help programmer to arrive at a flexible class design.

  1. Single Responsibility Principle
  2. Open Closed Principle
  3. Liskov Substitution Principle
  4. Interface Segregation Principle
  5. Dependency Inversion Principle

SOLID Principles

  1. Single Responsibility Principle: It states that there can only be one change in the software that could potentially change the specification of the class. This is because a class should only perform one kind of task. This is important to keep in mind because SRP reduces merge conflicts, and incompatibility issues when multiple people are working on the same project and hence makes version control easier.
  2. Open-Closed Principle: The open-closed principle simply states that classes should be open to extension while remaining closed to modification. In simpler words, we should be able to add new functionalities to our class without having to change pre-written code inside of our class.
  3. Liskov Substitution Principle: This is a rather hard intuition. In words, this states that all extended classes should be able to work using inputs of the type of super class and not produce any bugs while doing it. Although this is the expected behavior, it is often violated.
  4. Interface Segregation Principle: This principle states that we should create multiple interfaces to deal with clients instead of one so that for extended classes which might not need some of the functionalities, the user should not have to deal with them at all. Instead, he/she should have the independence to choose from the possible interfaces.
  5. Dependency Inversion Principle: Closely knit with the Open Closed Principle, Dependency Independence principle states that classes should rely on abstract classes and interfaces and not on rigid concrete functions and classes.

All the above five principles are collectively called SOLID principles. Note that there are a few more principles that will be useful in OOD.


Last Updated : 30 Oct, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads