Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #17779

Re: multiple inheritance

From Lew <noone@lewscanon.com>
Newsgroups comp.lang.java.programmer
Subject Re: multiple inheritance
Date 2012-08-12 20:19 -0700
Organization albasani.net
Message-ID <k09rnd$l7l$1@news.albasani.net> (permalink)
References <ad4daccd-4c15-4121-85e8-e8684c32b8a8@googlegroups.com> <3bdk189lqa3ktvsjel20hdee3gh6f5mj5j@4ax.com> <50286fa2$0$289$14726298@news.sunsite.dk>

Show all headers | View raw


Arne Vajhøj wrote:
> Roedy Green wrote:
>> 1. It has interfaces which gives much of the ability at lighter
>> weight..
>
> Only for a very limited type of types (those with no implementation
> at all).

That is true, but "very limited" might be misconstrued as "not very useful". 
That Java limits multiple inheritance to interfaces is a design decision of 
the language, and confers advantages. These advantages come to the fore when 
one follows various recommended practices such as those found in Joshua 
Bloch's /Effective Java/.

There are vanishingly few cases where one cannot mix in implementation through 
a combination of composition and single inheritance of implementation ('class' 
parent types) to accomplish with equal facility what multiple implementation 
inheritance would. Avoiding the sorts of downsides mentioned upthread is the 
motivation.

There are many times one wishes to guarantee the presence of a contractual 
method that is required by several interfaces. 'java.lang.Runnable' need not 
be the only interface to specify 'void run();'. Let's say you have a custom 
'Raceable' interface that also specifies 'void run();'. There's every reason 
to let an algorithm that expects a 'Raceable' to use some concrete type's 
'run()' even if it also serves to keep 'Runnable''s promise. Multiple 
inheritance of promises is easier to understand and keep bug free.

This ties into a programming approach I call "type-based programming". Given 
some concrete type

  public class FormulaOne implements Runnable, Raceable
  {
    @Override
    public void run() { ... }
  }

client code can freely say:

   FormulaOne fone = new FormulaOne();
   Raceable raceable = fone;
   Runnable runnable = fone;

and so forth. Only signatures are shared, so implementation won't be confused.

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

multiple inheritance bob smith <bob@coolfone.comze.com> - 2012-08-01 19:28 -0700
  Re: multiple inheritance markspace <-@.> - 2012-08-01 20:07 -0700
    Re: multiple inheritance Gene Wirchenko <genew@ocis.net> - 2012-08-01 21:07 -0700
  Re: multiple inheritance Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-01 23:12 -0400
  Re: multiple inheritance Joshua Cranmer <Pidgeot18@verizon.invalid> - 2012-08-01 23:41 -0400
    Re: multiple inheritance Lew <lewbloch@gmail.com> - 2012-08-02 01:05 -0700
    Re: multiple inheritance Arne Vajhøj <arne@vajhoej.dk> - 2012-08-12 23:15 -0400
  Re: multiple inheritance Roedy Green <see_website@mindprod.com.invalid> - 2012-08-02 01:10 -0700
    Re: multiple inheritance Arne Vajhøj <arne@vajhoej.dk> - 2012-08-12 23:08 -0400
      Re: multiple inheritance Lew <noone@lewscanon.com> - 2012-08-12 20:19 -0700
        Re: multiple inheritance Arne Vajhøj <arne@vajhoej.dk> - 2012-08-17 22:33 -0400
      Re: multiple inheritance Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-08-13 05:55 -0500
        Re: multiple inheritance markspace <-@.> - 2012-08-13 07:58 -0700
        Re: multiple inheritance Arne Vajhøj <arne@vajhoej.dk> - 2012-08-17 22:38 -0400
  Re: multiple inheritance Jan Burse <janburse@fastmail.fm> - 2012-08-02 10:12 +0200

csiph-web