Re: horizontal reuse: traits vs. grafts

From: Date: Thu, 25 Mar 2010 22:31:53 +0000
Subject: Re: horizontal reuse: traits vs. grafts
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-47628@lists.php.net to get a copy of this message
On 25.03.2010, at 21:23, Stefan Marr wrote:

> Hi:
> 
> 
> On 24 Mar 2010, at 17:58, Jonathan Bond-Caron wrote:
>> One thing I feel is missing from the RFC is how is_a() and instanceof are
>> affected with traits or grafts.
> Well, my personal (I admit very academic) position is:
> - Traits are not classes
> - Traits are not interfaces
> - Traits are not types
> - Traits cannot be instantiated 
> 
> Thus, there is no meaning of a is_a and instanceof, and it would not provide any meaningful
> information since you can exclude methods from a Trait in a composition.
> 
> Thus, you should resort to interfaces for use-case where you need to ensure that an object
> provides a certain set of methods.
> 
> Traits are purely for behavior, the class hierarchy or interface should provide the
> type-information/relations.
> 
> 
>> It's seem to me that a defining a 'trait' should be advertised strictly as
>> an 'advanced multiple inheritance technique' to reuse pieces of code and it
>> shouldn't be considered as an object (grafts proposal).
> It is not an object, right. You can not instantiate traits.
> But, I would not speak of multiple inheritance. I would prefer something along the lines of
> 'sustainable copy'n'past reuse'.


I think Stefan used the right metaphor in the RFC: its language level copy paste.

regards,
Lukas Kahwe Smith
mls@pooteeweet.org





Thread (21 messages)

« previous php.internals (#47628) next »