line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DesignPattern::Factory::Creator; |
2
|
|
|
|
|
|
|
$VERSION = '0.01'; |
3
|
2
|
|
|
2
|
|
8
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
55
|
|
4
|
2
|
|
|
2
|
|
9
|
use Carp; # nice errors |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
107
|
|
5
|
2
|
|
|
2
|
|
9
|
use vars qw( $VERSION ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
399
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# constructor |
8
|
|
|
|
|
|
|
sub new |
9
|
|
|
|
|
|
|
{ |
10
|
1
|
|
|
1
|
1
|
3
|
my $class = shift; |
11
|
1
|
|
|
|
|
5
|
return bless {}, $class; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub FactoryMethod |
15
|
|
|
|
|
|
|
{ |
16
|
0
|
|
|
0
|
1
|
0
|
die ('FactoryMethod not implemented'); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub AnOperation |
20
|
|
|
|
|
|
|
{ |
21
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
22
|
1
|
|
|
|
|
5
|
$self->{product} = $self->FactoryMethod(); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
1; |
26
|
|
|
|
|
|
|
=head1 NAME |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
DesignPattern::Factory::Creator - a participant in the Perl implementation of the Factory Method. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 DESCRIPTION |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
DesignPattern::Factory::Creator is the superclass of DesignPattern::Factory::ConcreteCreator. That is, ConcreteCreator inherits all methods from Creator, but can override these methods by implementing its own methods. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
From GOF, the DesignPattern::Factory::Creator class: |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
- declares the factory method, which returns an object of type DesignPattern::Factory::Product. DesignPattern::Factory::Creator may also define a default implementation of the factory method that returns a default DesignPattern::Factory::ConcreteProduct object. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
- may call the factory method to create a Product object. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 new() |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Constructor for this class. Usage: |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $object = DesignPattern::Factory::Pattern->new(); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 FactoryMethod() |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
The default FactoryMethod just dies with an error, thus ensuring that all subclasses implement a working version of this method. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 AnOperation() |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Calls FactoryMethod() and stores the result. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 AUTHOR |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Nigel Wetters (nwetters@cpan.org) |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 COPYRIGHT |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Copyright (c) 2001, Nigel Wetters. All Rights Reserved. This module is free software. |
61
|
|
|
|
|
|
|
It may be used, redistributed and/or modified under the same terms as Perl itself. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |