Results 1 to 7 of 7

Thread: IOC Definition

  1. #1
    Join Date
    Jan 2009
    Location
    Pune
    Posts
    58

    Default IOC Definition

    Hi,

    Can anybody tell me the exact definition of Inversion of Control with example.
    i.e technical flow ? How exactly it working?

    Thanks in advance
    Malhar

  2. #2
    Join Date
    Jan 2009
    Location
    Pune
    Posts
    58

    Default

    Is this ok?

    Definition of IOC : Inversion of control is based on the phenomenon that says when ever dependency between two classes (say class A and class B) now if A needs to access the methods of B then following our traditional approach, we go ahead and create an object of B in A.
    But as the fact of matter B is there to serve A but not A serving B creating objects for B.
    So in IOC the class B will try to inject its object into A rather than A creating object of B. so the control is reversed during the run time now spring container takes care which class object to inject into other class. So here class B inject its dependency in class A using constructor or setter.
    So here the statement works "Don't call me, I call you", class B calls class A even if class A needs the object B.

    ???
    Please tell me..

  3. #3
    Join Date
    Apr 2006
    Location
    South Carolina
    Posts
    122

    Thumbs up Spring Dependency Injection

    Your wording was a bit confusing to me, but I think you're getting there. Allow me to clarify one of your points.

    Quote Originally Posted by Malhar View Post
    So in IOC the class B will try to inject its object into A rather than A creating object of B. so the control is reversed during the run time now spring container takes care which class object to inject into other class. So here class B inject its dependency in class A using constructor or setter.
    You are exactly correct in that A needs to use B, but A doesn't create B. Just to help you understand how Spring uses IoC, though, B does not inject itself into A. (I suppose it could, but that is not how Spring does it.) Spring acts as a third party -- lets call it class C for example -- which constructs B and injects that copy of B into A. Thus neither A nor B have to know anything about each other. B does not inject itself into A; C injects B into A.

    Let me know if this is clear.

  4. #4
    Join Date
    Jan 2009
    Location
    Pune
    Posts
    58

    Default

    Hi Bron,

    Really thanks for guide me to understand, how exact IOC uses by Spring framework.

    If I am correct, Spring container inject the copy of object. right?

  5. #5
    Join Date
    Apr 2006
    Location
    South Carolina
    Posts
    122

    Thumbs up

    Quote Originally Posted by Malhar View Post
    If I am correct, Spring container inject the copy of object. right?
    That is correct.

  6. #6
    Join Date
    Jan 2009
    Location
    Pune
    Posts
    58

    Default

    So we can say it like:

    Definition of IOC : Inversion of control is based on the phenomenon that says when ever dependency between two classes
    (say class A and class B) now if A needs to access the methods of B then following our traditional approach, we go ahead and create
    an object of B in A.
    In Spring IOC, Spring container creates a object of class B and insert the copy of that object into class A by using setter
    injection or constructor injection. Thus neither A nor B have to know anything about each other.
    Simply stated, in IoC, instead of an application calling the framework, it is the framework that calls the components
    specified by the application.

  7. #7
    Join Date
    Jun 2009
    Posts
    2

    Default

    hey it really help me to understand the concept

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •