Re: General Question about Config Files and IoC

Paul Hammant <[email protected]> Mon, 16 Feb 2004 22:04:07 +0000
Newsgroups gmane.comp.java.jcontainer.interest
Message-ID <[email protected]>
Peter, Chad,

>
>> Do I need to make a separate "ObjectAConfig" class, which just holds 
>> the config settings from the file, and then have a constructor like 
>> this:
>>   new ObjectA(objectAConfig, objectB)
>>
>> Is this the preferred approach, or am I missing something?
>
>
> I believe that is the preferred approach when doing constructor-based 
> dependency injection.
>
> Of course, it doesn't have to be an 'ObjectAConfig' class, it could be 
> a Properties object, a DOM document, or anything else.. but there is 
> the general principal of passing a representation of the config via 
> the constructor. 


I'd always suggest not doing a Properties or DOM object via the ctor. It 
is too vague.  An interface to represent the the configuration, with 
multiple possible implementations is my preference.

- Paul