On 5/12/06, Torsten Curdt <[EMAIL PROTECTED]> wrote:
> the small problem with that or any factory is the use of a String to
> request a behavior means the compiler cannot know for sure if that
> code will work.

And this is a problem why?

I think it would be great to be able to just pass in a file object
into the factory that will look e.g. at the file extension (or even
header) and figure out what archiver to use. Otherwise you *always*
have to implement that part yourself.

Checking the result of a factory for null or throwing an exception is
common practise and I cannot really see real benefit of the
compile-time check here.
There are probably always going to be archivers that compress is not
going to support. So the factory *cannot* always return an instance
...unless you do all the checking

if (".zip".equals(extension)) -> ArchiveType.ZIP.newInstance();
if (".rar".equals(extension)) -> ArchiveType.RAR.newInstance();
...

in you code - which is cumbersome IMO.

In that situation you'd use: ArchiveType.valueOf(extension).newInstance()

--
Sandy McArthur

"He who dares not offend cannot be honest."
- Thomas Paine

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to