{
package Product;
use Moose::Role;
requires &
}
{
package Factory;
use Moose::Role;
requires &
requires &
sub create {
my ( $self, $owner ) = @_;
my $p = $self->create_product($owner);
$self->register_product($p);
$p;
}
}
{
package IDCard;
use Moose;
use Perl6::Say;
with &
has owner => ( is => &
sub use {
my $self = shift;
say $self->owner . "のカードを使います";
}
}
{
package IDCardFactory;
use Moose;
use Moose::Autobox;
with &
has owners => ( is => &
sub create_product {
my ( $self, $owner ) = @_;
IDCard->new( owner => $owner );
}
sub register_product {
my ( $self, $product ) = @_;
$self->owners->push( $product->owner );
}
}
sub main {
my $factory = IDCardFactory->new;
my $card1 = $factory->create("結城浩");
my $card2 = $factory->create("とむら");
my $card3 = $factory->create("佐藤花子");
$card1->use;
$card2->use;
$card3->use;
}
main();