3/16/2025

IoC vs DI vs DIP

 1.Inversion of Control (IoC)

A fundamental principle that inverts traditional control flow
Enables decoupling of components from their dependencies
Provides flexibility in how objects are created and managed

2.Dependency Inversion Principle (DIP)

A design guideline that specifies how modules should relate
Ensures high-level modules don't depend directly on low-level ones
Promotes abstraction-based relationships

3.Dependency Injection (DI)

A concrete technique for implementing IoC
Provides a specific mechanism for delivering dependencies
Helps achieve the goals outlined by DIP

IoC is the broad principle that enables various patterns, DIP guides how modules relate to each other, and DI provides a specific technique for implementing both concepts. Together, they form a powerful foundation for building maintainable software systems.

3/15/2025

Liskov Substitution Principle


Without LSP:
Example, we are creating different robots, Kawasaki, Yaskawa, and ABBRobots all inheriting IRobots and have methods like Connect(), Operate() , Move(). Later say some new functionality in ABBRobots like ReportFaultData() is introduced, so we need to added ReportFaultData() in interface and other robots should do " throw NotSupportedException("Reporting fault data is not supported");" , this leads to compile time error or we need to do nothing, and so we need to change other classes.

With LPS:
Instead we will create new interface ISupportsFaultDataReporting and add the new ReportFaultData() and inherit only for ABBRobots 
public class ABBRobots : IRobots, ISupportsFaultDataReporting 
{
}