Re: Java Feature Proposal
From: christopher diggins (cdiggins_at_users.sourceforge.net)
Date: 02/05/04
- Next message: xarax: "Re: Adding lightweight scripting"
- Previous message: John C. Bollinger: "Re: How to write a file in the root of my webapp"
- In reply to: Adam Jenkins: "Re: Java Feature Proposal"
- Next in thread: Dale King: "Re: Java Feature Proposal"
- Reply: Dale King: "Re: Java Feature Proposal"
- Reply: Adam Jenkins: "Re: Java Feature Proposal"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: xarax: "Re: Adding lightweight scripting"
- Previous message: John C. Bollinger: "Re: How to write a file in the root of my webapp"
- In reply to: Adam Jenkins: "Re: Java Feature Proposal"
- Next in thread: Dale King: "Re: Java Feature Proposal"
- Reply: Dale King: "Re: Java Feature Proposal"
- Reply: Adam Jenkins: "Re: Java Feature Proposal"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|