SOLID principles in Object Oriented Programming

HIRUSHA
4 min readFeb 27, 2021

--

What is S.O.L.I.D. ???

“The five fundamental concepts of object-oriented programming when designing Software applications”

History…

* Invented by ROBERT C. MARTIN in 2000
* S.O.L.I.D acronym was Introduced in 2004 by MICHAEL FEATHERS

S.O.L.I.D. Principles..

  • Single Responsibility Principle
  • Open-Closed Principle
  • Liskov Substitution Principle
  • Interface Segregation Principle
  • Dependency Inversion Principle
S.O.L.I.D Principles of OOP Design

01) Single Responsibility Principle (S.R.P)

Single Responsibility Principle (S.R.P)

This theory suggests that only one thing can be achieved by an individual.
Single obligation, then, denotes some isolated work. As a consequence, once we have a computing entity that executes calculations, the only justification to modify it is that the calculations themselves need to be modified.

Benefits -

  • It is easier to understand the Class.
  • The class is less difficult to keep up with.
  • The class has a greater reusability.

02) Open-Closed Principle (O.C.P.)

Open-Closed Principle (O.C.P.)

This theory suggests that programming should only be changed to correct bugs and mistakes, and that new classes should be used to expand functionality. Usually, the new class will be a derivative class or a generic base class to facilitate code reuse from the original. This theory inevitably contributes to the development of abstract base classes and the inclusion of new sub classes to expand functionality.

Benefits -

  • The class was robust, flexible and reusable.
  • Can’t add any bugs
  • Via testing, more stable over time

03) Liskov Substitution Principle (L.S.P.)

Liskov Substitution Principle (L.S.P.)

This theory suggests that objects in a program should be able to be replaced with instances of their subtypes without compromising the program’s correctness. If you pass a subset of an abstraction, make sure you don’t modify the parent abstraction’s actions or state semantics.

Benefits -

  • The construction of inheritance mechanisms that show high levels of inheritance coupling.
  • The resultant classes are cohesive in the inheritance system.

04) Interface Segregation Principle.(I.S.P.)

Interface Segregation Principle.(I.S.P.)

It is about how interfaces should be written. But what has been stated? Essentially, if an interface gets too large / heavy, it must be separated into smaller, more precise interfaces. And the protocol will be determined by the client who will use it, meaning that the interface’s client will only be aware of the methods that are important to them.

Benefits -

  • Reusability
  • Maintainability
  • Faster Compilation

05)Dependency Inversion Principle (D.I.P.)

Dependency Inversion Principle (D.I.P.)

Usually, high-level components in a software program must depend on lower-level components. When low-level components are ‘hard-coded’ into high-level components, two problems.

The first issue is one of testability. Writing unit tests for the high-level components becomes difficult, if not impossible, since they are often referred to as low-level components, which can depend on items like database links or documents.

One of re-usability is the second issue. When they are coded to unique low level applications, it becomes very difficult to re-use the high level components. Flexibility and code reuse are hindered as a result.

To solve these issues, insert or pass an interface representing the lower level classes to the higher level classes, allowing them to call the code on the interface.

Benefits -

  • Reusable
  • Scalable

Benefits Of S.O.L.I.D. …

  • Single Responsibility. It’s easier to follow, understand, debug, drop, and refactor if the code conforms to this one.
  • Open/Closed In terms of time and risks, modifications and use of items become cheap by following it.
  • Liskov Substitution.
  • Segregation of Interfaces.
  • Inversion of Dependencies.
Benefits Of S.O.L.I.D. …

--

--

HIRUSHA
HIRUSHA

Written by HIRUSHA

3rd Year Software Engineering Undergraduate

No responses yet