·
SOLID principles basically form the fundamental guidelines for building
👉 object-oriented ,
👉 loosely coupled ,
👉 robust, maintainable and
👉 easily understandable applications .
A class should depend on abstraction ✅(interfaces and abstract classes) and not on concretion (classes).
For ex:
Above code will work for one engine but what if there are two types of engine,
say diesel and petrol,it would mean to modify our class which is not ❌ good idea.
This can be solved by adding ➕ an abstraction layer ,
so car instead of directly depending on Engine now depends on EngineInterface:
PetrolEngine or DieselEngine classes implement this interface
and we can connect any of these to the Car class: