Re: Multiple Inheritance Needed in OOP?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxx

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux