Re: General Question about Config Files and IoC

peter royal <[email protected]> Tue, 17 Feb 2004 19:29:12 -0500
Newsgroups gmane.comp.java.jcontainer.interest
Message-ID <[email protected]>
On Feb 17, 2004, at 6:52 PM, Chad Woolley wrote:
> What are the reasons for using an interface rather than an plain class 
> as the configuration parameter?

You want to make a re-usable component for other people, really.

> I'm sure there are good reasons to use an interface, but I'd like to 
> hear some concrete examples, because this is an issue that I think 
> about a lot.  It seems to me that there is a lot of overhead to 
> extract out and maintain a well-documented interface that duplicates 
> the real class, "just in case someone ever wants an alternate 
> implementation".  I have trouble thinking of real examples that 
> justify this extra work.

Say there was a ServletContainerComponent that took a 
ServletContainerConfig .. if ServletContainerConfig was an interface, 
then I would have lots of flexibility in deciding where that 
configuration information comes from..

    * I could load it from a properties file
    * Extract it from a centralized config file for my app
    * Load it from a database
    * ... etc ...

While all the same could be done if it was a class, I'd then have some 
util method whose sole purpose was populating a ServletContainerConfig 
object.. with an interface I could create a custom impl and keep the 
logic in a more "attached" place, as it were..
-pete