| Bio::Phylo::Factory - Creator of objects, reduces hardcoded class names in code |
Bio::Phylo::Factory - Creator of objects, reduces hardcoded class names in code
use Bio::Phylo::Factory; my $fac = Bio::Phylo::Factory->new; my $node = $fac->create_node( '-name' => 'node1' );
# prints 'Bio::Phylo::Forest::Node' print ref $node;
The factory module is used to create other objects without having to 'use' their classes.
new()
Factory constructor.
Type : Constructor Title : new Usage : my $fac = Bio::Phylo::Factory->new; Function: Initializes a Bio::Phylo::Factory object. Returns : A Bio::Phylo::Factory object. Args : (optional) a hash keyed on short names, with class names for values. For example, 'node' => 'Bio::Phylo::Forest::Node', which will allow you to subsequently call $fac->create_node, which will return a Bio::Phylo::Forest::Node object. (Note that this example is enabled by default, so you don't need to specify it.)
Type : Factory methods Title : create Usage : my $foo = $fac->create('Foo::Class'); Function: Creates an instance of $class, with constructor arguments %args Returns : A Bio::Phylo::* object. Args : $class, a class name (required), %args, constructor arguments (optional)
register_class()
Registers the argument class name such that subsequently
the factory can instantiates objects of that class. For
example, if you register Foo::Bar, the factory will be
able to instantiate objects through the create_bar()
method.
Type : Factory methods Title : register_class Usage : $fac->register_class('Foo::Bar'); Function: Registers a class name for instantiation Returns : Invocant Args : $class, a class name (required), or 'short_name' => $class, such that you can subsequently call $fac->create_short_name()
Also see the manual: the Bio::Phylo::Manual manpage and http://rutgervos.blogspot.com.
$Id: Factory.pm 1171 2009-07-07 06:23:58Z rvos $
| Bio::Phylo::Factory - Creator of objects, reduces hardcoded class names in code |