Question

We know what Run time/Dynamic polymorphism is in OOP (principle #1). Inversion of Control simply means (by definition on wiki) Inversion Of Control (principle #2)

How do you differentiate these two; can we say #1 is superset of #2. If not how do we differ or say they are similar

Was it helpful?

Solution 2

I'm not an expert about IoC and DI (dependency injection), but I guess you have been misled by the fact that IoC uses polymorphism to provide dependencies to a class in a loose-coupled way.

You provide (inject) an object of a class, implementing some interface or superclass, to another object.

But, IoC and polymorphism are very different concepts:

  • Polymorphis is one of the fundamentals of OO languages.
  • IoC is a design pattern.

OTHER TIPS

so reading more certain IOC implementation (dependency injection) is certainly an usage of dynamic polymorphism. So certainly these (#1 and #2) are different concepts, but they do have some common grounds. For these two we can never say one concept is superset of the other.


From wiki pages

Implementation techniques (section of IOC)

In object-oriented programming, there are several basic techniques to implement inversion of control. These are:

-1- Using a factory pattern
-2- Using a service locator pattern
-3- Using a dependency injection, for example:
    -a- A constructor injection
    -b- Parameter injection
    -c- A setter injection
    -d- An interface injection
-4- Using a contextualized lookup
-5- Using Template method design pattern
-6- Using strategy design pattern

Dependency injection is something which is based on the idea of Runtime/Dynamic polymorphism

IoC is simply your object exposes an interface for anyone willing to use it making it his problem how and when he will do that (has nothing to do with static typing or method dispatch - it's a pure API thing).

Polymorphism is rather the ability to use exact object's type behaviour at runtime changing the way methods are dispatched, say, if they are overridden and all that with preserving type safety.

Don't know even how to compare these two.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top