Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

How to build a dependency injection framework by myself?

Thread view: 
moop™ - 24 Aug 2006 05:15 GMT
Hi,
I am using a factory class to build instances. the factory method looks
like:

<code>
class MyFactory{
Item getItem(String key){
..}
}
</code>

and the key and class are configured in a file
key=com.abcd.ClassA
b=com.abcd.B

<code>Item</code> is an interface implemented by some of the above
classes mentioned inside the cofiguration file.

I want the factory class to read the configuration file and then
instantiate the given class and as a return value. But I have no idea
how to instantiate the class. I tried Class.forName() and seesm it is
not a good solution to this problem.
Andrew Thompson - 24 Aug 2006 05:44 GMT
Sub: How to build a dependency injection framework by myself?

<quips>
A general answer to ..
"How to xxx a yyy by myself?"
..might start with..

1) Don't request help from other people.
..
</quips>

..oh, and I don't know what the experts on this
sort of stuff will say, but it seems unlikely that
it will be possible to do 'plug-ins' without at
least a little classloader trickery..

Andrew T.
Chris Uppal - 24 Aug 2006 10:46 GMT
moopT wrote:

> I want the factory class to read the configuration file and then
> instantiate the given class and as a return value. But I have no idea
> how to instantiate the class. I tried Class.forName() and seesm it is
> not a good solution to this problem.

Assuming you want to do this yourself in order to learn about the relevant
techniques, why not start by looking at something small, such as picocontainer,
and see what they do ?  Then read up on the classes, methods, and techniques
they use.

By all means ask more questions as you learn, but this isn't really the sort of
forum for a full description of the architectural options and challenges.

Also, a related question comes up fairly often here.  Try checking Google's
archives for posts about "pluggable" components.

   -- chris
AndrewMcDonagh - 24 Aug 2006 18:56 GMT
moop™ wrote:
> Hi,
> I am using a factory class to build instances. the factory method looks
[quoted text clipped - 18 lines]
> how to instantiate the class. I tried Class.forName() and seesm it is
> not a good solution to this problem.

why on earth bother?

just download PicoContainer - it does this exact thing and more and is
fully tested and proved to work.
PerfectDayToChaseTornados - 24 Aug 2006 19:57 GMT
> Hi,
> I am using a factory class to build instances. the factory method looks
[quoted text clipped - 18 lines]
> how to instantiate the class. I tried Class.forName() and seesm it is
> not a good solution to this problem.

Download Spring http://www.springframework.org/download, look at the source
code.

Signature

pdtct



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.