Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #17864 > unrolled thread
| Started by | "Arne Vajhøj" <arne.vajhøj@1:261/38.remove-odu-this> |
|---|---|
| First post | 2012-08-13 19:38 +0000 |
| Last post | 2012-08-18 19:38 +0000 |
| Articles | 6 — 5 participants |
Back to article view | Back to comp.lang.java.programmer
Re: multiple inheritance "Arne Vajhøj" <arne.vajhøj@1:261/38.remove-odu-this> - 2012-08-13 19:38 +0000
Re: multiple inheritance "Lew" <lew@1:261/38.remove-odu-this> - 2012-08-13 19:38 +0000
Re: multiple inheritance "Arne Vajhøj" <������
høj@1:261/38.remove-7rm-this> - 2012-08-18 19:37 +0000
Re: multiple inheritance "Leif Roar Moldskred" <leif.roar.moldskred@1:261/38.remove-odu-this> - 2012-08-13 19:38 +0000
Re: multiple inheritance "markspace" <markspace@1:261/38.remove-odu-this> - 2012-08-13 19:38 +0000
Re: multiple inheritance "Arne Vajhøj" <������
høj@1:261/38.remove-7rm-this> - 2012-08-18 19:38 +0000
| From | "Arne Vajhøj" <arne.vajhøj@1:261/38.remove-odu-this> |
|---|---|
| Date | 2012-08-13 19:38 +0000 |
| Subject | Re: multiple inheritance |
| Message-ID | <50294F05.56813.calajapr@time.synchro.net> |
To: Roedy Green From: "Arne Vajhoj" <arne.vajhoj@1:261/38.remove-nlb-this> To: Roedy Green From: Arne Vajhoj <arne@vajhoej.dk> On 8/2/2012 4:10 AM, Roedy Green wrote: > On Wed, 1 Aug 2012 19:28:31 -0700 (PDT), bob smith > <bob@coolfone.comze.com> wrote, quoted or indirectly quoted someone > who said : > >> Why doesn't Java support multiple inheritance? > > 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). > 2. Java originally was intended for set top boxes. That is too > heavyweight a feature. C++ is used a lot in embedded context, so that argument does not hold water. > 3. Study Eiffel. implementing it is quite tricky, especially when you > get name clashes. > > you might see it in Java 11 or so, or whatever language inherits the > Java mantle. Not likely. It is not desirable. Arne -+- BBBS/Li6 v4.10 Dada-1 + Origin: Prism bbs (1:261/38) -+- Synchronet 3.16a-Win32 NewsLink 1.98 Time Warp of the Future BBS - telnet://time.synchro.net:24 --- BBBS/Li6 v4.10 Dada-1 * Origin: Prism bbs (1:261/38) --- Synchronet 3.16a-Win32 NewsLink 1.98 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [next] | [standalone]
| From | "Lew" <lew@1:261/38.remove-odu-this> |
|---|---|
| Date | 2012-08-13 19:38 +0000 |
| Message-ID | <50294F05.56815.calajapr@time.synchro.net> |
| In reply to | #17864 |
To: Arne Vajhøj
From: "Lew" <lew@1:261/38.remove-nlb-this>
To: Arne Vajhoj
From: Lew <noone@lewscanon.com>
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
-+- BBBS/Li6 v4.10 Dada-1
+ Origin: Prism bbs (1:261/38)
-+- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24
--- BBBS/Li6 v4.10 Dada-1
* Origin: Prism bbs (1:261/38)
--- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Arne Vajhøj" <������ høj@1:261/38.remove-7rm-this> |
|---|---|
| Date | 2012-08-18 19:37 +0000 |
| Message-ID | <502FE75F.56988.calajapr@time.synchro.net> |
| In reply to | #17867 |
To: Lew
From: "=?UTF-8?B?QXJuZSBWYWpow7hq?=" <=?utf-8?b?qxjuzsbwywpow7hq?=@1:261/38.rem
ove-rj6-this>
To: Lew
From: =?UTF-8?B?QXJuZSBWYWpow7hq?= <arne@vajhoej.dk>
On 8/12/2012 11:19 PM, Lew wrote:
> 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.
Indeed.
Implementation inheritance is not in fashion in Java, so interfaces is the
majority of cases.
A classic text:
http://www.artima.com/intv/gosling34.html
> 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 some solutions to those problems. But Java was designed to be simple,
so we got what we got.
Arne
-+- BBBS/Li6 v4.10 Dada-1
+ Origin: Prism bbs (1:261/38)
-+- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24
--- BBBS/Li6 v4.10 Dada-1
* Origin: Prism bbs (1:261/38)
--- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Leif Roar Moldskred" <leif.roar.moldskred@1:261/38.remove-odu-this> |
|---|---|
| Date | 2012-08-13 19:38 +0000 |
| Message-ID | <50294F06.56818.calajapr@time.synchro.net> |
| In reply to | #17864 |
To: Arne Vajhøj
From: "Leif Roar Moldskred" <leif.roar.moldskred@1:261/38.remove-nlb-this>
To: Arne Vajhoj
From: Leif Roar Moldskred <leifm@dimnakorr.com>
Arne Vajh-,j <arne@vajhoej.dk> wrote:
> On 8/2/2012 4:10 AM, 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).
At times, I've wished that Java had automatic delegation (composition) in
addition to inheritance and interface implementation, where the compiler
automatically adds the public methods and fields from delegated objects, except
when there's a conflict of names. Something like this, maybe:
public class ClassAlfa {
public void alfaMethod( ) { ... }
public void sharedMethod( ) { ... }
public void anotherSharedMethod( ) { ... }
}
public class ClassBeta {
public void betaMethod( ) { ... }
public void sharedMethod( ) { ... }
public void anotherSharedMethod( ) { ... }
}
public class Delegator {
private delegate ClassAlfa ALFA;
private delegate ClassBeta BETA;
public void sharedMethod( ) {
ALFA.sharedMethod( );
}
public void anotherSharedMethod( ) {
ALFA.sharedMethod( );
BETA.sharedMethod( );
}
}
public class Example {
public static void main( String[] args ) {
private Delegator delegator;
delegator.alfaMethod( );
delegator.betaMethod( );
delegator.sharedMethod( );
delegator.anotherSharedMethod( );
}
}
--
Leif Roar Moldskred
-+- BBBS/Li6 v4.10 Dada-1
+ Origin: Prism bbs (1:261/38)
-+- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24
--- BBBS/Li6 v4.10 Dada-1
* Origin: Prism bbs (1:261/38)
--- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "markspace" <markspace@1:261/38.remove-odu-this> |
|---|---|
| Date | 2012-08-13 19:38 +0000 |
| Message-ID | <50294F07.56820.calajapr@time.synchro.net> |
| In reply to | #17870 |
To: Leif Roar Moldskred
From: "markspace" <markspace@1:261/38.remove-nlb-this>
To: Leif Roar Moldskred
From: markspace <-@.>
On 8/13/2012 3:55 AM, Leif Roar Moldskred wrote:
> Arne Vajh-,j <arne@vajhoej.dk> wrote:
>> On 8/2/2012 4:10 AM, 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).
>
> At times, I've wished that Java had automatic delegation (composition)
"Automatic delegation" is what I want. I've even invented my own little syntax
for it:
public SomeClass extends Fubar implements List(myList), OtherThing {
private AbstractList myList = new ArrayList();
...
}
where the parenthesis in the interface list is a forward declaration to a field
that will be the delegate for that particular interface. It really shouldn't
be that hard to do, just a few synthetic methods.
I really rather upset that we aren't getting something like this with Java 8. I
don't see any reason not to fix this right now, honestly.
-+- BBBS/Li6 v4.10 Dada-1
+ Origin: Prism bbs (1:261/38)
-+- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24
--- BBBS/Li6 v4.10 Dada-1
* Origin: Prism bbs (1:261/38)
--- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Arne Vajhøj" <������ høj@1:261/38.remove-7rm-this> |
|---|---|
| Date | 2012-08-18 19:38 +0000 |
| Message-ID | <502FE760.56992.calajapr@time.synchro.net> |
| In reply to | #17870 |
To: Leif Roar Moldskred
From: "=?UTF-8?B?QXJuZSBWYWpow7hq?=" <=?utf-8?b?qxjuzsbwywpow7hq?=@1:261/38.rem
ove-rj6-this>
To: Leif Roar Moldskred
From: =?UTF-8?B?QXJuZSBWYWpow7hq?= <arne@vajhoej.dk>
On 8/13/2012 6:55 AM, Leif Roar Moldskred wrote:
> Arne Vajh-,j <arne@vajhoej.dk> wrote:
>> On 8/2/2012 4:10 AM, 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).
>
> At times, I've wished that Java had automatic delegation (composition)
> in addition to inheritance and interface implementation, where the
> compiler automatically adds the public methods and fields from
> delegated objects, except when there's a conflict of names. Something
> like this, maybe:
>
>
> public class ClassAlfa {
> public void alfaMethod( ) { ... }
> public void sharedMethod( ) { ... }
> public void anotherSharedMethod( ) { ... }
> }
>
> public class ClassBeta {
> public void betaMethod( ) { ... }
> public void sharedMethod( ) { ... }
> public void anotherSharedMethod( ) { ... }
> }
>
>
> public class Delegator {
> private delegate ClassAlfa ALFA;
> private delegate ClassBeta BETA;
>
> public void sharedMethod( ) {
> ALFA.sharedMethod( );
> }
>
> public void anotherSharedMethod( ) {
> ALFA.sharedMethod( );
> BETA.sharedMethod( );
> }
> }
>
> public class Example {
> public static void main( String[] args ) {
> private Delegator delegator;
>
> delegator.alfaMethod( );
> delegator.betaMethod( );
> delegator.sharedMethod( );
> delegator.anotherSharedMethod( );
> }
> }
You IDE should be able to generate the code for you.
But it could save some code in some cases.
Arne
-+- BBBS/Li6 v4.10 Dada-1
+ Origin: Prism bbs (1:261/38)
-+- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24
--- BBBS/Li6 v4.10 Dada-1
* Origin: Prism bbs (1:261/38)
--- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web