Re: Java Feature Proposal

From: christopher diggins (cdiggins_at_users.sourceforge.net)
Date: 02/05/04


Date: Thu, 5 Feb 2004 14:54:27 -0500


"Adam Jenkins" <adam@remove.thejenkins.me.org> wrote in message
news:4022703A.4010502@remove.thejenkins.me.org...
> christopher diggins wrote:
> > "BarryNL" <barry@nospam.nl> wrote in message
> >>>Would anyone else like this feature?
> >>
> >>Nope. I think it would be quite confusing. Do you have a concrete
> >>example in mind? Everything I can think of where this might be useful is
> >>better served by using an Adapter or Proxy pattern.
> >
> >
> > There is a more concrete example at
> > http://www.heron-language.com/extensions.html . The patterns you mention
> > have little, if anything, to do with what I am proposing.
>
> Ok, I just read that. As far as I can tell, your
> interfaces-with-extensions are exactly equivalent to abstract classes
> with a special restriction on the definition of the non-abstract
> methods, namely that the definitions may only call methods of the class
> they're defined in. By playing semantic games you're calling these
> "interfaces" instead of "abstract classes", thereby allowing you to add
> multiple-inheritance to Java without calling it that.
>
> Your extra restriction does not get rid of any of the problems with
> multiple inheritance. For instance:
>
> interface ISomeInterface1 {
> contract void Foo();
> extension void DoSomething() { Foo(); }
> }
>
> interface ISomeInterface2 {
> contract void Bar();
> extension void DoSomething() { Bar(); }
> }
>
> class SomeClass implements ISomeInterface1, ISomeInterface2
> {
> public void Foo() { System.out.println("Foo()"); }
> public void Bar() { System.out.println("Bar()"); }
>
> public static void main(String[] args) {
> SomeClass instance = new SomeClass();
> instance.DoSomething();
> }
> }
>
> What will this program print when run? Which implementation of
> DoSomething() will be called? It was precisely to avoid these kinds of
> ambiguities, and the complex rules needed to deal with them, that
> multiple-inheritance was left out of Java.

I responded previously to Anton Spaans with regards to this issues, you need
simply cast to the appropriate interface in order to resolve the naming
conflict (just as you would with any interface naming conflict). This is not
a complicated rule. The extensions proposal does not introduce any new
problems that do not already occur with naming conflicts with multiple
implementation of interfaces.

Interfaces with extensions do not have fields, so there is no chance of
multiple inheritance of fields which was the only big problem of [poorly
used] MI.

> Other than the fact that they can't be multiply inherited, abstract
> classes can provide the same functionality as you're proposing. Just
> consider the abstract methods to be the contract, and the non-abstract
> methods to be the extensions.

Yes abstract base classes could be used similarly except that you can't have
multiple inheritance of ABC's, and an abstract class can have fields. An
abstract base class can also partially implement the contract of another
abstract base class.

I also wish to point out that by your argument all interfaces in general can
be replaced entirely by abstract base classes.

Thanks for your comments,

-- 
Christopher Diggins
yet another language designer
http://www.heron-language.com


Relevant Pages

  • Re: soapsuds for binary
    ... > singlecalls behind the scenes with session passed in transparently). ... but why interfaces and not abstract base classes? ... it seems more appropriate to be using abstract base ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Java Feature Proposal
    ... > conflict. ... No, there is no naming conflict with Java interfaces, since they contain ... class to inherit multiple conflicting implementations of a method. ... I don't see why multiple inheritance of fields is any more of a problem ...
    (comp.lang.java.programmer)
  • Re: IDropSource and IDataObject Multiple Inheritance
    ... COM does not support multiple inheritance for interfaces. ... apartment model of the object and the apartment model of the ... One of this is invoked by ActiveXContainer and anothere by WindowsShell. ...
    (microsoft.public.win32.programmer.ole)
  • Re: Former C++ Programmer Approaches Lisp
    ... >> multiple inheritance but this is as close as we can get. ... > I think this is an overly simplistic way to view interfaces. ... Interfaces compromise by not allowing state to ... interfaces can only contain abstract methods. ...
    (comp.lang.lisp)
  • Re: interface question
    ... IRoadVehicle and RoadVehicle are ... and is certainly a water vehicle. ... Interfaces and inheritance both represent ...
    (microsoft.public.dotnet.languages.csharp)