DesignPattern::Factory::Creator - a participant in the Perl implementation of the Factory Method.


DesignPattern-Factory documentation Contained in the DesignPattern-Factory distribution.

Index


Code Index:

NAME

Top

DesignPattern::Factory::Creator - a participant in the Perl implementation of the Factory Method.

DESCRIPTION

Top

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.

From GOF, the DesignPattern::Factory::Creator class:

- 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.

- may call the factory method to create a Product object.

new()

Constructor for this class. Usage:

  my $object = DesignPattern::Factory::Pattern->new();

FactoryMethod()

The default FactoryMethod just dies with an error, thus ensuring that all subclasses implement a working version of this method.

AnOperation()

Calls FactoryMethod() and stores the result.

AUTHOR

Top

Nigel Wetters (nwetters@cpan.org)

COPYRIGHT

Top


DesignPattern-Factory documentation Contained in the DesignPattern-Factory distribution.

package DesignPattern::Factory::Creator;
$VERSION = '0.01';
use strict;
use Carp; # nice errors
use vars qw( $VERSION );

# constructor
sub new
{
    my $class = shift;
    return bless {}, $class;
}

sub FactoryMethod
{
    die ('FactoryMethod not implemented');
}

sub AnOperation
{
    my $self = shift;
    $self->{product} = $self->FactoryMethod();
}

1;