Re: horizontal reuse: traits vs. grafts
| From: | Stefan Marr | Date: | Thu, 25 Mar 2010 20:23:12 +0000 |
| Subject: | Re: horizontal reuse: traits vs. grafts | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-47618@lists.php.net to get a copy of this message | ||
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'.
Best regards
Stefan
--
Stefan Marr
Software Languages Lab
Vrije Universiteit Brussel
Pleinlaan 2 / B-1050 Brussels / Belgium
http://soft.vub.ac.be/~smarr
Phone: +32 2 629 2974
Fax: +32 2 629 3525