I have a question about designing Moose classes: I have a module A which has multiple features B, C, D, because multiple people will work on these and it would be nice to have this logical separation of the different features. The features B, C, D need to have access to A themselves (they run something on A).
I want to put A, B, C, D, ... into different files.
The user should only have to instantiate A and then use the other classes through it, such as:
my $a = A->new(); $a->b->method(); $a->c->another_method();
package A; has b => ( isa => 'B' ); has c => ( isa => 'C' ); sub BUILD { my ($self) = @_; $self->b(B->new(a => $self)); $self->c(C->new(a => $self)); } package B; has a => ( isa => 'A', required => 1); sub method { my ($self) = @_; $self->a->exec(...); # Stuff related to B } package C; has a => ( isa => 'A', required => 1); sub another_method { my ($self) = @_; $self->a->exec(...); # Stuff related to C }
But this solution doesn't seem to be very 'clean' apart from that it does what it should. It's not making use of any OO concepts, it's just hardcoding the different classes together.
I'm not very familiar with Moose Roles, could I use those to achieve the desired behavior?
In reply to Moose design question by elTriberium
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |