The Artima Developer Community
Sponsored Link

Great Question



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.


Great Question

Posted by Bill Venners on 02 Dec 1998, 4:33 PM

> If Interfaces are so useful in Java, why is it that you did
> not make use of pure virtual base classes in C++?

Wow, you are very good at finding holes in arguments. Perhaps
you should be a lawyer. Perhaps you are a lawyer. Regardless,
you found an inconsistency in my argument that I hadn't even

Indeed, if interfaces are so useful in Java, why didn't I make
use of pure virtual base classes in C++?

I didn't, because I had never heard of anyone using pure virtual
classes in the way I now use Java interfaces, and I never
thought of it myself. This lack of experience with the concept
is why it was a struggle for me, coming from C++, to wrap
my brain around interfaces in Java.

>Is there some difference between them which make the Java
interface easier to use?

I don't think Java interfaces are easier to use than C++
pure virtual classes. I just think that Java interfaces, because
they are their own construct, force us to figure out what to use
them for.

I think the fact that James Gosling pulled interfaces out and
gave pure virtual classes their own keyword and special syntax
shows that software people, through experience using and
struggling with existing OO programming languages, were
becoming aware of how important this interface thing can be
in making flexible designs.

> Has Java, by disallowing multiple implementation inheritance,
> made you take the step of separating implementation from
> interface in a way you would not have done without being
> forced to?

I wouldn't put it that way. I'd say that Java forced me to
think about why pure virtual classes are useful, and eventually
I saw the light. Now I use them. Which leads to your last

> Also, if you now went back to C++ would you now make much
> more use of virtual base classes than you did before?


The programming languages we use don't force us to
think in any certain way, but they encourage us to think about
design in certain ways. For example, I could go out and write
a completely procedural program in Java if I wanted. But I
wouldn't do that in Java. If I were writing a C program, on
the other hand, I'd think structured, procedural design, even
though I'm a big fan of object-oriented thinking and with effort
I could probably implement an object-oriented design in C.

Java's interface, because it was a separate construct and the
only way to do multiple inheritance in Java, encouraged me by
its mere presence to think about why fully abstract base
classes that can be multiply inherited are useful. Eventually,
I "got it" and to some extent I now approach object-oriented
designs differently.

Thanks for your question.



Sponsored Links

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