Re: stupid beginner question

[prev] [thread] [next] [Date index for 2005/06/28]

From: Rob Kinyon
Subject: Re: stupid beginner question
Date: 19:59 on 28 Jun 2005
On 6/28/05, Hartmaier Alexander <Alexander.Hartmaier@xxxxxxxxx.xx> wrote:
> 1. Can you explain 'factory class' to me?

I don't know about the rest of it, but a factory class is a class
whose only job is to create instances of other classes. So, let's say
you have a PetShop class that has a buy_pet() method. You would pass
in the species of the pet you wanted to buy and it would return you an
object corresponding to the pet. So, something like:

my $new_pet =3D PetShop->buy_pet( species =3D> 'Cat', age =3D> 'baby' );
my $other_pet =3D PetShop->buy_pet( species =3D> 'doberman', color =3D> 'bl=
ack' );

PetShop takes care of all the requisite loading of classes and any
other required bookkeeping.

If you want a real-world example, take a look at Excel::Template,
particularly Excel::Template::Factory. There, the factory also handles
isa() calls, so I can say $some_node->isa( 'IF' ) and the factory will
DWIM.

Rob

stupid beginner question
Hartmaier Alexander 13:47 on 24 Jun 2005

Re: stupid beginner question
Matt S Trout 18:26 on 24 Jun 2005

Re: stupid beginner question
Hartmaier Alexander 07:11 on 27 Jun 2005

Re: stupid beginner question
William Ross 09:35 on 27 Jun 2005

Re: stupid beginner question
Hartmaier Alexander 09:46 on 27 Jun 2005

Re: stupid beginner question
Hartmaier Alexander 09:24 on 28 Jun 2005

Re: stupid beginner question
William Ross 10:21 on 28 Jun 2005

Re: stupid beginner question
Hartmaier Alexander 16:51 on 28 Jun 2005

Re: stupid beginner question
Rob Kinyon 19:59 on 28 Jun 2005

Generated at 16:35 on 28 Jul 2005 by mariachi v0.52