I have to create an UML class diagram from the following example code (Perl). I don't think that the standard factory pattern match in my case or I don't understand it correctly. I don't have AbstractFactory
and ConcreteFactory
but a single Factory
.
What does this example looks like in UML class diagram?
Edit: This is only a very flat and simple example. The real application has many "Types" with totally different workflows. The class diagramm is to get an overview over the hole structure. Not realy for internal workflow like sequence diagrams does.
package Module::Factory;
sub new { bless { type => $_[1] }, $_[0]; }
sub create {
my( $self, $name ) = @_;
my $object = "Module::Types::$self->{type}"->new( $name );
return( $object );
}
package Module::Types::Test1;
sub new { bless { name => $_[1] }, $_[0]; }
sub test {
my( $self ) = @_;
say "Hello, $self->{name}.";
return( $self );
}
package Module::Types::Test2;
sub new { bless { name => $_[1] }, $_[0]; }
sub test {
my( $self ) = @_;
say "Bye, $self->{name}.";
return( $self );
}
# even more Module::Types::TestN packages...
package main;
foreach my $type ( qw( Test1 Test2 ) ) {
my $factory = Module::Factory->new( $type );
foreach my $name ( qw( World John Peter ) ) {
my $object = $factory->create( $name );
$object->test();
}
}
Factory->new('test')
your concrete factory implementation?