I would say that I had not heard of traits though I remember somewhere a mention of roles in perl 6. While reading the first few posts, a question formed in my mind "How are roles/traits different to interfaces?". Indeed your language in this post convinced me to post this.
...you can query the class to find out what traits/roles it implements.
| [reply] |
"How are roles/traits different to interfaces?"
An interface (in the Java sense) has no implementation, it is only a "signature" which the consumer of the interface promises to conform to.
Roles/Traits are allowed to have implementations. The methods in a trait are "flattened" into the consuming class. This is not all that different from just "exporting" methods from the trait's namespace into the classes namespace, except that there are a set of "rules" and "guidelines" set out in the Traits papers (see the SEE ALSO section of Class::Trait for some good links). These rules and guidelines actually make it so that Trait ordering is irrelevant, which right there removes a lot of the issues normally associated with MI and mix-ins.
| [reply] |