The Artima Developer Community
Sponsored Link

Java Answers Forum
Starting using Inversion of Control

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Calum MacLean

Posts: 9
Nickname: calummacle
Registered: Feb, 2003

Starting using Inversion of Control Posted: Dec 22, 2004 2:33 AM
Reply to this message Reply
Advertisement
Hi

I have an existing (Java desktop) application, which I'm looking at converting to use Inversion of Control principles. I'm just starting to look at the Java containers - HiveMind, Pico, Spring etc.

I'm not sure about how components/services/objects always have to be instantiated, rather than retrieved from an existing object.

In my application, I have a IHandler interface, a single instance of which is used by a number of objects.
Currently, the instance is supplied by an Engine class, which has an inner class implementing IHandler, and a getHandler() method which returns an instance of the inner class.

I'm wondering how, when using Inversion of Control, I can supply this instance of IHandler to the objects which require it.
Most of the containers seem to require that the instance is created.
However, in this case, the instance should be returned from an existing object (which will also have been created by the container).

What's the best way to deal with this situation?
I could, for example, make the IHandler inner class to be a public class, so it can be instantiated directly. But I'm not convinced that exposing the class in this way is the ideal way to do this.

Thanks for your help,
Calum

Topic: Problem with packaged applet in HTML page Previous Topic   Next Topic Topic: Leading Zeros are dropped?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use