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.

cheers
--
Torsten

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

Reply via email to