On Mar 24, 3:00 pm, "Matt Humphrey" <ma...@iviz.com> wrote:
> <horo...@gmail.com> wrote in message
>
> news:684f647a-c9e1-419c-8299-...>I had a quick question about implementing interfaces and storing those
> > implementations..
>
> > suppose I have a implementation that I defined:
>
> I think you mean interface.
>
yeah, you are right, I am tired..

>
>
> > package mycom;
>
> > public interface MyInterface
> > {
> > public void mymethod();
> > }
>
> > and I put it in file:
>
> > mycom/MyInterface.java
>
> > and I want to have several different implementations defined for it,
> > that I want to stick under:
>
> > mycom/MyInterface/Implentation1.java
> > mycom/MyInterface/Implentation2.java
> > mycom/MyInterface/Implentation3.java
>
> > Can you do this? when I go to make my Implementation1, I say
> You appear to be mixing up the package and class names. The class is not
> itself a package that you can put things under. (You can nest classes
> within another class, but that's an entirely different issue.)
yeah, I sort of gathered that you couldn't do this, but I think that
is more a limitation of java than anything else. You may argue not so
for interfaces, because you can have a class implement many of them
(and hence the 'inheritance' tree is really a bush), but for an
abstract class - or any arbitrary class for that matter - I think it
is a lot clearer to have an inherited class tied to its parent in a
very clear way.
Consider the whole reader design decision in java. I personally think
that
Reader.InputStream
is a lot clearer than
InputStreamReader
because it implicitly shows the relationship between the two classes,
and lends itself to a hierarchy
(like files inside a directory belong to that directory). Likewise,
I'd like to be able to name my class 'File', and hnece say:
Semaphore.File sf = new Semaphore.File()
because I'm using a *type* of Semaphore. I do admit that an abstract
class works better in this case than an interface, but as it is I need
to manually mangle the name to avoid conflict with java's File class.
Anyways, I don't want to make this a big deal, I'll work with it. It's
not like I have any choice.
ed