3 ms·
Neat. This style of code reuse is a lot like perl6 roles (http://search.cpan.org/~rkinyon/Perl6-Roles-0.01/lib/Perl6/Roles.pm http://search.cpan.org/~rkinyon/Pe
by substack 16y ago
Neat. This style of code reuse is a lot like perl6 roles (http://search.cpan.org/~rkinyon/Perl6-Roles-0.01/lib/Perl6/Roles.pm http://search.cpan.org/~rkinyon/Perl6-Roles-0.01/lib/Perl6/R...) or haskell typeclasses: instead of describing how objects fit into a taxonomic hierarchy, objects or typeclasses are described by what behaviors they fulfill. For instance, in haskell a Complex type has an instance of Num in order to define numeric operations like (+) and (-). The emphasis is on what something does rather than on what it is.
- draegtun 16y agoFor perl5 then Moose Roles would be more appropriate. I have posted a few links about roles to HN. Below are probably best ones: * http://news.ycombinator.com/item?id=1552691 http://news.ycombinator.com/item?id=1552691 * http://news.ycombinator.com/item?id=774694 http://news.ycombinator.com/item?id=774694 * http://news.ycombinator.com/item?id=588391 http://news.ycombinator.com/item?id=588391 * http://news.ycombinator.com/item?id=1620295 http://news.ycombinator.com/item?id=1620295
- eitland 16y ago>instead of describing how objects fit into a taxonomic hierarchy, objects or typeclasses are described by what behaviors they fulfill. Can't this be said about Java interfaces too?
- chromatic 16y agoYes and no. Java interfaces are a very degenerate case of roles. They provide no default behavior (a few constants notwithstanding), they are special cases in at least part of the type system (declaring a class does not also declare a role), and I know of no good way to handle conflicts when implementing multiple interfaces with overlapping requirements.