Everything you should know about SOLID principles

Everything you should know about SOLID principles

Become a Better Object-Oriented Programmer: Mastering the SOLID Principles

·

2 min read

Quick Summary of the Blog:-

  1. About SOLID principles

  2. Advantages/ When to use?

  3. Disadvantages/ When not to use?

About SOLID principles:-

A set of rules that provides guidelines for writing maintainable, extensible, and testable code. By following these principles, you can create code that is easier to understand, modify, and reuse.

S: Single Responsibility Principle

1. There should be only one reason to modify the class, which means one class should have it's clear and only one responsibility.
2. Find out the one reason to change class and take out everything else from that class.
3. Put very precise names for small classes and generic names for large classes.

O: Open/Closed Principle

1. Classes/Entities should be open for extendibility but closed for modification. Example:- The libraries could be extended but they do not allow to modify their implementation.

L: Liskov Substitute Principle

1. We should be able to replace any superclass with another sub-class without affecting the existing functionality.
2. Client should be unaware of the implementation.

I: Interface Segregation Principle

1. Client should not be forced to implement all the methods or properties whether it is using that or not.
2. Interfaces should be segregated at a such level so that the client should implement only the method it is using.

D: Dependency Inversion Principle

1. High-level modules should not depend on low-level modules, which means both should depend on abstraction.
2. Able to change the implementation of the low-level modules without altering the code of the high-level modules.

Advantages/ When to use? (Please follow this link-> LinkedIn Article)

Disadvantages/ When not to use? (Please follow this link-> LinkedIn Article)