SOLID Principles

Taşkın Binbir
2 min readSep 19, 2021

Hello everybody,

What is SOLID principle ? What is definition of the SOLID ? I am going to answer these questions.

Definition of the SOLID is:

Single Responsibility Principle

Open/Closed Principle

Liskov’s Substitution Principle

Interface Segregation Principle

Dependency Inversion/Injection Principle

Let me explain these principles.

Single Responsibility Principle

“Don’t repeat yourself”

A component should only be used one way.

If the component serves more than one purpose, then it violates this principle.

Designing the code as small and purposeful components increases reusability.

Smaller components make it more comfortable and more understandable.

Open/Closed Principle

A component should be closed to change and able to development.

Generally useful for solving backward compatibility issues.

For example, instead of changing our Calculate class later, creating a NewCalculate class by inheriting from it and override the code in it.

Liskov’s Substitution Principle

Objects should be able to change the expectations of the program with their children.

Things to know: Invariants, Post-conditions and Pre-conditions.

Configure pre-conditions before processing anything.

Configure post-conditions after processing Invariants.

Post-conditions shouldn’t change the Invariants in the ancestor class when we substrate.

New conditions not able be added to Pre-conditions.

Interface Segregation Principle

This principle introduced to prevent code that uses other classes from reaching more than they need, thereby increasing readability and maintainability. The functions is classes are divided by coherent and minor interfaces.

It wants classes that receive participation from each other to be able to be changed without problems and without breaking the system.

Its main purpose is to ensure that other codes, which we call client using the interfaces in your code, do not see more code than they need.

Dependency Inversion Principle

It is a principle that works in demanding the dependent components, not the creation demanding the dependent components.

Dependency injection is an implementation of dependency inversion.

Instead of producing it ourselves, we want it from someone else.

--

--