Re: Desing Question re Multiple Constructors
- From: <Mike>
- Date: Sun, 30 Oct 2005 02:45:25 +0100
"Rhino" wrote:
>I have a design question about constructors.
>
....
> I've just finished writing a class that creates a JComponent which
> displays
> images: static and animated GIFs, JPGs, and PNGs. The images can originate
> anywhere:
> - in a standalone file on the file system, e.g. file:d:\\myImages\\foo.gif
> - in a standalone file online, e.g. http://shazam.com/images/bar.gif
> - in a jar on the filesystem, e.g.
> jar:file:d:\\myJars\\test.jar!/Images/baz.gif
> - in a jar that is online, e.g.
> jar:http://shazam.com/images/test.jar!/Images.baz.gif
> - in a jar that is in the application's classpath, e.g.
> jar:file!/Images/baz.gif
>
> The sources of the images are identified, initially, as Strings, as you
> can
> see in the examples above. In effect, I am using three standard protocols
> to
> describe the locations:
> - file: (for standalone files on the filesystem)
> - http: (for standalone files online)
> - jar: (for images found in jars, regardless of whether they are online,
> in
> the filesystem, or in the classpath)
>
[big snip]
Hi,
Well, let me look at this as if I was a potential user of your class.
You have a constructor with a String. You analyse the String to determine
how the file must be loaded. This kind of constructor would be practical if
it could be used intuitively. But it's not. Firstly there is no way to know
what protocol can be used (but by looking at the javadocs of the constructor
(up to date?), which will become unpractical if there are too many
protocols). Secondly the user must use a specific construction for the
different protocols. I don't know the jar protocol and I see that there is a
!-token somewhere in it. For an other protocol there could be a $ or a &
somewhere, as a user I don't want to be bothered with such things.
You've added other constructors with FileLocation, JarLocation,
OnlineLocation as argument. Making different classes for the different
location types is better than using a String, but make sure these Location
objects can be created in a user friendly way. There is no need for
different constructors. Make a Location class or interface, make one
constructor with a Location argument and let the FileLocation, JarLocation,
OnlineLocation classes extends / implements the Location class / interface.
Mike
.
- Follow-Ups:
- Re: Desing Question re Multiple Constructors
- From: Rhino
- Re: Desing Question re Multiple Constructors
- Prev by Date: testing methods
- Next by Date: Re: tictactoe
- Previous by thread: Re: Desing Question re Multiple Constructors
- Next by thread: Re: Desing Question re Multiple Constructors
- Index(es):
Relevant Pages
|