SOLID principle is one of the most important design principles in OOP languages like Java, Python, C#, etc.
Sadly, most of the programmers find it super difficult to understand.
Here's the simplest guide to understand SOLID principles:
Sadly, most of the programmers find it super difficult to understand.
Here's the simplest guide to understand SOLID principles:
1. Full form
S = Single Responsibility Principle
O = Open/Closed Principle
L = Liskov Substitution Principle
I = Interface Segregation Principle
D = Dependency Inversion Principle
(we will use Java to understand them)
S = Single Responsibility Principle
O = Open/Closed Principle
L = Liskov Substitution Principle
I = Interface Segregation Principle
D = Dependency Inversion Principle
(we will use Java to understand them)
2. Single Responsibility
A class should always have one responsibility and there should be only a single reason to change it.
A class should always have one responsibility and there should be only a single reason to change it.
3. Open Close
Class should be Open for Extension but Closed for Modification.
Class should be Open for Extension but Closed for Modification.
4. Liskov Substitution
Child Classes should be replaceable with Parent Classes without breaking the behavior of our code.
Child Classes should be replaceable with Parent Classes without breaking the behavior of our code.
5. Interface Segregation:
Interface should only have methods that are applicable to all child classes.
If an interface contains a method applicable to some child classes then we need to force the rest to provide dummy implementation.
Move such methods to a new interface.
Interface should only have methods that are applicable to all child classes.
If an interface contains a method applicable to some child classes then we need to force the rest to provide dummy implementation.
Move such methods to a new interface.
6. Dependency Inversion
Class should depend on abstractions (interface and abstract class) instead of concrete implementations.
It makes our classes de-coupled with each other.
If implementation changes then the class referring to it via abstraction won't change.
Class should depend on abstractions (interface and abstract class) instead of concrete implementations.
It makes our classes de-coupled with each other.
If implementation changes then the class referring to it via abstraction won't change.
Hope you find it useful!
📣 Announcement
You can now have a conversation with me!
If you're feeling stuck in your tech career and need personalized guidance, you can book a 1:1 call with me.
Visit topmate.io for more information.
📣 Announcement
You can now have a conversation with me!
If you're feeling stuck in your tech career and need personalized guidance, you can book a 1:1 call with me.
Visit topmate.io for more information.
Loading suggestions...