Re: Desing Question re Multiple Constructors
- From: "Rhino" <no.offline.contact.please@xxxxxxxxxx>
- Date: Sun, 30 Oct 2005 08:31:26 -0500
<Mike> wrote in message news:436425b4$0$11072$e4fe514c@xxxxxxxxxxxxxxxxx
> "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.
>
Okay, both of those strike me as reasonable criticisms of an approach based
on a single constructor using a String.
> 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.
>
Sorry, I'm not getting a clear picture of what you mean here. Can you give
me a few lines of code that will help me understand how the Location
class/interface will look and how the subclasses/implementors of Location
will look? No need to be terribly detailed. Also, what are the
advantages/disadvantages of using an interface versus a class for Location?
Sorry, but, like I said, my OO theory is pretty weak in some respects and I
find I still don't really think in OO very naturally.
Rhino
.
- References:
- Re: Desing Question re Multiple Constructors
- From: Mike
- Re: Desing Question re Multiple Constructors
- Prev by Date: 2nd time around with help for java
- Next by Date: Re: Desing Question re Multiple Constructors
- Previous by thread: Re: Desing Question re Multiple Constructors
- Next by thread: testing methods
- Index(es):
Relevant Pages
|
|