Announcement Announcement Module
Collapse
No announcement yet.
IOC Definition Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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..

    Comment


    • #3
      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.

      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.

      Comment


      • #4
        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?

        Comment


        • #5
          Originally posted by Malhar View Post
          If I am correct, Spring container inject the copy of object. right?
          That is correct.

          Comment


          • #6
            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.

            Comment


            • #7
              hey it really help me to understand the concept

              Comment


              • #8
                What I read I really liked it. Thank you for your information!

                Comment

                Working...
                X