I have been studying the TT quite a bit recently because I am writing a tool that is quite heavily based on it. I have noticed that it uses several Design Patterns. I am particularly interested in Template/Config.pm which to me appears to impliment the AbstractFactory Pattern. I noticed that it also use the FactoryMethod pattern ie most of its class methods are FactoryMethod's. I have implimented a very similar method for creating objects but I have used a single FactoryMethod. I was wondering if there where any gotchas that I have not forseen in the code below.

sub factory_method {
    my $class  = shift;
    my $create_this_class  = shift;
    my $params = defined($_[0]) && UNIVERSAL::isa($_[0], 'HASH')
           ? shift : { @_ };
    return undef unless $class->load( $create_this_class );
    return $create_this_class->new($params)
        || $class->error("failed to create $create_this_class : ");
}

The above method is called as

CMS::Config->factory_method( $CMS::Config::PAGE_MANAGER, $config ));

where

$PAGE_MANAGER = 'CMS::Manager::Page';

and $config is a referance to a hash


Disadvantages I can see with the above single factory_method are.

1. If the Object to be created does not use the "new".
2. If parameters need to be handled or passed in differently
3. Some sort of pre-init work needs to be carried out

I imagine there are patterns that deals with these occourances.

Harry

_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to