Multiple Inheritance Needed in OOP?

Multiple Inheritance Needed in OOP?

am 29.12.2009 04:45:03 von Daniel Kolbo

Hello,

Okay so PHP designers explicitly decided against multiple inheritances,
but aren't there legitimate needs for multiple inheritance in OOP?

For example, consider the following three classes (A,B,C) with the
following properties (a number is a distinct property or method).

A: 1, 2, 3
B: 1, 3
C: 1, 2,

I would like to set the 3 classes up so that no object has 'extra'
properties than it requires, so that no property has to be
declared/defined in two or more classes, and so that we are strictly
using single inhertiance. I don't think it's possible. I've been
incorrect beforee...If i'm incorrect please let me know how to set this
up as a single inhertance class structure.

If this is not possible, why doesn't the PHP community implement
multiple inheritance? (I'm anticipating that someone will say, you
simply need to redefine what you are calling your objects so that the
properties do permit a single inheritance...)

I'm very interested to hear why there is the dogma of single inheritance
only.

Thanks,
dK
`

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Multiple Inheritance Needed in OOP?

am 29.12.2009 06:02:09 von Larry Garfield

On Monday 28 December 2009 9:45:03 pm Daniel Kolbo wrote:
> Hello,
>
> Okay so PHP designers explicitly decided against multiple inheritances,
> but aren't there legitimate needs for multiple inheritance in OOP?
>
> For example, consider the following three classes (A,B,C) with the
> following properties (a number is a distinct property or method).
>
> A: 1, 2, 3
> B: 1, 3
> C: 1, 2,
>
> I would like to set the 3 classes up so that no object has 'extra'
> properties than it requires, so that no property has to be
> declared/defined in two or more classes, and so that we are strictly
> using single inhertiance. I don't think it's possible. I've been
> incorrect beforee...If i'm incorrect please let me know how to set this
> up as a single inhertance class structure.
>
> If this is not possible, why doesn't the PHP community implement
> multiple inheritance? (I'm anticipating that someone will say, you
> simply need to redefine what you are calling your objects so that the
> properties do permit a single inheritance...)
>
> I'm very interested to hear why there is the dogma of single inheritance
> only.
>
> Thanks,
> dK
> `

Because pure multiple inheritance can lead to all sorts of highly weird
behavior when you don't know which parent class you mean at any given time.
Single inheritance is just easier to wrap your head around, and wrap the
compiler's head around.

What you're looking for is composition, which can do pretty much what you're
looking for. See my last reply to you on this list from Christmas day.

There's been some discussion of implementing "traits" in later versions of
PHP, but no concrete patches so far.

--
Larry Garfield
larry@garfieldtech.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Multiple Inheritance Needed in OOP?

am 30.12.2009 01:24:47 von Daniel Kolbo

Larry Garfield wrote:
> On Monday 28 December 2009 9:45:03 pm Daniel Kolbo wrote:
>> Hello,
>>
>> Okay so PHP designers explicitly decided against multiple inheritances,
>> but aren't there legitimate needs for multiple inheritance in OOP?
>>
>> For example, consider the following three classes (A,B,C) with the
>> following properties (a number is a distinct property or method).
>>
>> A: 1, 2, 3
>> B: 1, 3
>> C: 1, 2,
>>
>> I would like to set the 3 classes up so that no object has 'extra'
>> properties than it requires, so that no property has to be
>> declared/defined in two or more classes, and so that we are strictly
>> using single inhertiance. I don't think it's possible. I've been
>> incorrect beforee...If i'm incorrect please let me know how to set this
>> up as a single inhertance class structure.
>>
>> If this is not possible, why doesn't the PHP community implement
>> multiple inheritance? (I'm anticipating that someone will say, you
>> simply need to redefine what you are calling your objects so that the
>> properties do permit a single inheritance...)
>>
>> I'm very interested to hear why there is the dogma of single inheritance
>> only.
>>
>> Thanks,
>> dK
>> `
>
> Because pure multiple inheritance can lead to all sorts of highly weird
> behavior when you don't know which parent class you mean at any given time.
> Single inheritance is just easier to wrap your head around, and wrap the
> compiler's head around.
>
> What you're looking for is composition, which can do pretty much what you're
> looking for. See my last reply to you on this list from Christmas day.
>
> There's been some discussion of implementing "traits" in later versions of
> PHP, but no concrete patches so far.
>

Hello Mr. Garfield,

I saw your reply on how to mimic composition, and I appreciate your
comments. I don't prefer (not saying that anyone really does) the mixin
approach as private/protected aspects of the mixined class are not
available in the pseudo-child class. Also, the code may still need to
be maintained in the child class for some changes in the parent class.

I would prefer to throw too much into my parent class then to deal with
the mixin approach (at this time).

I understand about a seemingly simple idea, being not so simple to
implement. However ;), for name conflict issues, the compiler could
have a simple rule. Such a proposed rule might be for the compiler to
throw a warning and to use the last definition supplied. This way
multiple inheritance is available for those that legitimately need it
and the warning is there so the 'spooky' behaviour scenario can be
isolated to an hesitance name conflict.

I was reading the request for comments about the traits. My thought is,
if we go through the work of allowing horizontal reuse into php, why not
do the work for multiple inheritance first.

I could understand having the default install to only single
inheritance, but i do not understand why php programmers are not, at
least, given the option.

Thanks,
dK
`

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Multiple Inheritance Needed in OOP?

am 30.12.2009 01:43:25 von Daniel Egeberg

On Wed, Dec 30, 2009 at 01:24, Daniel Kolbo wrote:
> This way multiple inheritance is available for those that legitimately need it [...]

Could you by any chance provide an example where multiple inheritance
would be required? To be honest, I've never really seen a use for it,
but that may be because I've not used a language that supports
multiple inheritance (not on classes anyway).

--
Daniel Egeberg

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Multiple Inheritance Needed in OOP?

am 30.12.2009 03:26:30 von Daniel Kolbo

Daniel Egeberg wrote:
> On Wed, Dec 30, 2009 at 01:24, Daniel Kolbo wrote:
>> This way multiple inheritance is available for those that legitimately need it [...]
>
> Could you by any chance provide an example where multiple inheritance
> would be required? To be honest, I've never really seen a use for it,
> but that may be because I've not used a language that supports
> multiple inheritance (not on classes anyway).
>

In the OP i had an example:
>> For example, consider the following three classes (A,B,C) with the
>> following properties (a number is a distinct property or method).
>>
>> A: 1, 2, 3
>> B: 1, 3
>> C: 1, 2,
>>
>> I would like to set the 3 classes up so that no object has 'extra'
>> properties than it requires, so that no property has to be
>> declared/defined in two or more classes, and so that we are strictly
>> using single inheritance.

Granted this example has the additional specifications of not having
inherited extra properties then needed and not having duplicated code.
This example doesn't 'require', multiple inheritance, as we could always
just throw all of our code (methods, properties) we would ever possibly
conceive of needing into one root class and have all classes extend the
root class. So no, there is no example where it would be absolutely
required, but i argue the above example legitimates the need for
multiple inheritance.

Other reasons:
If the only way to make your classes follow strict single inheritance is
to reduce readability and/or confuse the intuitive understanding of the
design's class model structure, then i would argue readable and
intuitive code is a legitimate reason (perhaps even a requirement ;)

Also, if one is trying to enhance a 3rd party's code, but the 3rd party
didn't provide access to the code (closed source) and/or they didn't
provide interfaces to allow for mixins.

Also, if you don't want to deal with the headache and drawbacks of mixins.

Also, if you want to ensure higher levels of code maintainability and so
don't want to duplicate code.

Also, if you are concerned about your code's efficiency and want to
avoid the situation of throwing in all the methods higher up the parent
class chain.

I think that this list of reasons (specifically maintainability,
readability, and efficiency) more than justifies the concern of
resolving namespace conflicts.

Thanks,
dK
`

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php