Login   Register  
PHP Classes
elePHPant
Icontem

traits are not multiple inheritance

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      PHP Classes blog  >  PHP 5.4 Alpha Feature...  >  All threads  >  traits are not multiple inheritance  >  (Un) Subscribe thread alerts  
Subject:traits are not multiple inheritance
Summary:a post about traits
Messages:3
Author:Stefan Jibrail Froelich
Date:2011-08-02 16:04:26
Update:2011-08-06 19:23:33
 

  1. traits are not multiple inheritance   Reply  
Picture of Stefan Jibrail Froelich
Stefan Jibrail Froelich
2011-08-02 20:03:11
Traits are more like mixins which allow us to achieve horizontal code reuse. This allows us to respect the DRY principle while allowing combinations of functionality easily. Imagine trying to build classes from permutations of BouncingBall, ColoredBall, FlyingBall and RollingBall. Or adding a persist method to User and Book without duplicating code.
A quick google of horizontal inheritance will give you loads of examples.

  2. Re: traits are not multiple inheritance   Reply  
Picture of Manuel Lemos
Manuel Lemos
2011-08-06 07:04:33 - In reply to message 1 from Stefan Jibrail Froelich
Ernani did not said traits are multiple inheritance, he just said it would be a way to achieve similar type of code reuse for those familiar with multiple inheritance.

  3. Re: traits are not multiple inheritance   Reply  
Picture of Stefan Jibrail Froelich
Stefan Jibrail Froelich
2011-08-06 19:23:33 - In reply to message 1 from Stefan Jibrail Froelich
'...it seems to be similar to inheritance, multiple inheritance, in a different way...'.
I wanted to point out that though it might seem that way, it shouldnt be confused with vertical inheritance.
Believe me, many of us follow this cast (i cant wait for the next one) and your words are like gold to us. Some newbie might take it as is. Thanks for the best repository by the way.