The Artima Developer Community
Sponsored Link




This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.



Posted by Bill Venners on 17 Nov 1998, 7:37 PM

> > Clearly, an interface is not a class, otherwise it wouldn't have been given its own special construct, right? Wrong!
> > Therein lies the problem: A Java interface IS a class - a purely abstract class.
> A class is a class too. It's also an Object. Does that make it NOT a class? This is flawed logic.
Here I feel I must defend Mike's statement. I think Ralph is
correct in saying that a "class" is not an "interface" in
strict Java jargon terms. According to the strict
way in which the Java specs use these words:

  • a class is a class
  • an interface is an interface
  • a class is not an interface
  • both classes and interfaces are types

But on the other hand, in the more general object oriented
meaning of the word class, Mike is right in saying that
Java's interface is just a special kind of class: a "purely
abstract class."

On the other hand, I think Ralph went too far when he claimed
that a class is also an object. Objects are instances of
classes. If a class were an architectural blueprint for a
house, an object would be a house. From the same blueprint,
you could fill a neighborhood with hundreds of instances of
the same class of house. Not necessarily a very nice
neighborhood, but that's progress.

Although it's usually not helpful to argue about terminology,
it's helpful to define your terms when you are trying to
debate the meaning behind the words.

> > Oooo, but I thought multiple inheritance was sooo BAD! Not so. If it were, only BAD programmers would use Java interfaces, and clearly this is not the case.
> > MI has, in fact, just one problem: A bad reputation, which stems almost solely from C++�s appalling support for MI.
> That and its common misuse by blurring implementation and interface.
> C++ supports interfaces. They're called pure virtual base classes.
> They aren't often used when designing except by OO purists.
I think Ralph is trying to get at a point I tried to make in
my article. My ultimate (so far) epiphany about interfaces was
that they were about something more fundamental
than multiple inheritance.

I got the feeling that James Gosling may have designed Java
the way he did to say to designers everywhere that this idea
of defining abstract interfaces that can be implemented in
multiple ways is important. The constructs of a programming
language influence how programmers think when they create
designs they ultimately intend to implement in that language.
I think James may have been trying to get us to think in
terms of separating interface from implementation when he gave
the concept of interface its own construct and syntax in Java.

This separation of interface from implementation is
a fundamental theme all over Java: the JVM, the APIs, the
language. In plain old software design, thinking in terms of
abstract interfaces that can have multiple implementations,
and just connecting the various parts of your system via the
interfaces, makes for more flexible software.

So, does that make any sense?



Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us