Inversion of Control & Dependency Injection

What is IOC Principle: Inversion of control (IoC) is a design principle in which custom-written portions of a computer program receive the flow of control from a generic framework.

In simple words, IOC is inverting the control from called class to calling class.

DI: Dependency Injection is a design principle in which code creating a new object supplies the other objects that the new object depends upon for operation. This is a special case of inversion of control. Often a dependency injection framework (or “container”) is used to manage and automate the construction and lifetimes of interdependent objects.

DI is ability to supply(inject) external dependencies into a class at run time. Continue reading “Inversion of Control & Dependency Injection”

Facade Design Pattern

Facade Pattern: A single class that represents the entire system. It is needed when one simple action needs many other action behind the scenes.

 

Example: A withdrawal from bank includes following actions

  1. Check if account is valid
  2. Check if Pin is valid
  3. Check if Amount is sufficient
  4. Make changes accordingly

Continue reading “Facade Design Pattern”