Various patterns to achieve IoC

Let's recall what the  Dependency Inversion Principle (DIP) states: high-level modules should not depend upon low-level modules; both should depend upon abstraction. This is a fundamental requirement for making any application modular and adjustable.

While designing any system, we should make sure that high-level classes do not instantiate low-level classes; instead, they should rely on abstraction (the interface or abstract class) rather than depending on other concrete classes directly. The DIP does not specify how this happens, so a technique is required to separate the low-level modules from the high-level modules. IoC provides this technique.

There are various patterns to achieve IoC, including inverting the object creation process from your class to some other class and reducing the coupling between modules or classes. Let's discuss these patterns, focusing more on how they decouple the modules and achieve separation of concerns:

  • The factory method pattern
  • The service locator pattern
  • The template method pattern
  • The strategy pattern

All of these patterns encapsulate a specific responsibility, which makes the system modular. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.12.156