I'm not a language purist by any means. I consider myself pragmatic, but realize I'm often idealistic. It's hard to reconcile those two ideas, though.
Consider polymorphism. I've most often seen it explained in terms of inheritance. I'm not a big fan of strong typing in general (at least as C and its descendants do it), but mixing polymorphism with the typing system seems... really wrong. Part of the reason Test::MockObject works is because polymorphism isn't limited to objects that share a common ancestor.
The secret is, objects which share a common interface are isomorphic.
Okay, it's not a very well-kept secret. Still, I've seen (and written) too much Perl code that relies on isa(). (Hey, at least I'm way over checking ref() so often!)
I'd like to see that Perl 6 doesn't encourage falling into that trap. At least, I'd like to see that Perl 6 encourages composition and delegation as well as it encourages inheritance. (Having failed to convince Allison completely through mad rhetorical skills, I resorted to code.)
In that light, I present Class::Interface. Please see the discussion at Perl Monks for more information.
As always, I may be way off track here. Once I figured out the way things really ought to work, though, they made a great deal more sense.
Looks interesting, but... (Score:2)
On the other hand, by writing a new module you could implement some useful stuff that Perl's OO left out, like compile-time checking of in
Re:Looks interesting, but... (Score:1)
Yes, you could override
isa(), or much about with the appropriate@ISA. However, per the example in the docs, anAirportis not anArcade. TheAirporthas anArcade. Surprisingly, the semantic distinction is important to me.Re:Looks interesting, but... (Score:2)
-sam
Re:Looks interesting, but... (Score:1)
That's exactly the point! Good thinking. :)
Using
isa()dictates that the implementation is inheritance (or, at least, that you have to fake up that you're inheriting).In Class::Interface, derived classes are automatically marked as implementing their parent class interfaces. Whether you inherit or not, by talking about interfaces instead you're saying "objects of this class can (or should) handle the messages an object of this type can". You just have to be a little more explicit if you're not s
Have you seen ex::interface? (Score:1)
Re:Have you seen ex::interface? (Score:1)
I didn't catch it on my first foray through the CPAN. Now that I've seen it, I see it does something I wanted to avoid.
One of my goals is to support mixins without giving up the possibility of having interface checking. One can imagine a module that provides mixins that, grouped together, form a named interface. Mixing them into a class is simple:
package RobotDog; use Animals mixin => ':Dog';RobotDogwould now be marked as implementing theDoginterface, and it has the doglike methods fromACompile time checking (Score:1)
Might slip in... (Score:1)
Re:Might slip in... (Score:1)
The nice part about does is that if you get it right, you get is for (almost) free! (That's assuming
Class::Interfacedoes it correctly, anyway.)Re:Might slip in... (Score:1)