in reply to Re: Abstract Methods in Moose
in thread Abstract Methods in Moose
I hadn't seen MooseX::ABC - apparently its author's intent was the same as mine, but there are some limitations in the implementation.
package AbstractWidget; use Moose; use MooseX::ABC; requires 'get_widget_type'; package LessAbstractWidget; use Moose; use MooseX::ABC; extends 'AbstractWidget'; package SnazzyWidget; use Moose; extends 'LessAbstractWidget'; sub get_widget_type{ "BasicWidget" } # BOOM: # AbstractWidget requires LessAbstractWidget to implement get_widget_t +ype
OK, but what you say about "specializing" or extending roles was a big eye-opener for me. I was caught thinking in terms of the Java paradigm, thinking of the Moose Role as something to be added into the base class. Instead, what works is when the Role itself acts as the base class, as you illustrated (and Anonymous Monk hinted at). I'm then free to extend/specialize the Role if I want.
The only thing that seems to suffer a little is the terminology - when I say that SnazzyWidget is with 'AbstractWidget', that implies that Snazzy Widget can in fact exist without Abstract Widget if it wanted to, which isn't true. But I think that's a consequence of this base class / concrete class model I have in my head, and my naming of the packages. If I called AbstractWidget something like Typeable instead - the class names would work together better, I think.
Thanks for your input, and also thanks much for your work on Moose. I've barely scratched the surface but I like what I've found so far. I mostly write throw-away Perl scripts for random ad-hoc data processing tasks. I like to model things in terms of OO, but have often shied away from it because of some of the verbosity and opaqueness (my $self = shift;, bless $self, __PACKAGE__, writing accessors etc.) of Perl 5 OO programming. Moose looks to have made it much more natural to work with objects in Perl 5.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Abstract Methods in Moose
by stvn (Monsignor) on Dec 13, 2009 at 00:38 UTC | |
Re^3: Abstract Methods in Moose
by stvn (Monsignor) on Dec 20, 2009 at 13:33 UTC |