What is Inversion of Control?
What is Inversion of Control?
Inversion of Control (IoC) and Dependency Injection (DI) are two related practices in software development which are known to lead to higher testability and maintainability of software products. these patterns are said to be based on a principle, which states: "don't call us, we'll call you".
If you follow these simple two steps, you have done inversion of control:
Inversion of control is a practical way to reduce code duplication, and if you find yourself copying an entire method and only changing a small piece of the code, you can consider tackling it with inversion of control. Inversion of control is made easy in many languages through the concept of delegates, interfaces, or even raw function pointers.
Examples
Inversion of Control (IoC) and Dependency Injection (DI) are two related practices in software development which are known to lead to higher testability and maintainability of software products. these patterns are said to be based on a principle, which states: "don't call us, we'll call you".
If you follow these simple two steps, you have done inversion of control:
- Separate what-to-do part from when-to-do part.
- Ensure that when part knows as little as possible about what part; and vice versa.
Inversion of control is a practical way to reduce code duplication, and if you find yourself copying an entire method and only changing a small piece of the code, you can consider tackling it with inversion of control. Inversion of control is made easy in many languages through the concept of delegates, interfaces, or even raw function pointers.
Examples
- Event Handling. Event Handlers (what-to-do part) while Raising Events (when-to-do part)
- Interfaces. Component client - an interface (when-to-do part) while Component Interface implementation (what-to-do part)
- Template method design pattern. template method when-to-do part -- primitive subclass implementation what-to-do part
Comments
Post a Comment