C
cnmaclean
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
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