Factory method

2001-10-18 Thread Nigel Wetters

I'm working through the design patterns book with some Java colleagues, 
trying to present Perl equivalents of their Java code - I call it 
pattern-oriented Perl ;)

At the moment, we're discussing the Factory method, and I've put together 
some sample code here:

http://www.perfascist.com/factory.tar.gz

I've built a test application (factory/test_list.pl), which sets up and 
calls some methods on two objects from the base class List (code for the 
List class is in factory/List.pm). In this particular example, the test 
script calls an object method 'content' which either lists a directory or 
lists a file, depending on what type of List object is instantiated.

The List class is nothing but a placeholder for its subclasses. When it's 
constructor method (sub new) is called, it creates an instance of one of its 
subclasses, the choice of subclass being based on one of the arguments to 
the constructor method. Thereafter, all calls to the List object redirect 
arguments to the subclass.

Inside the subclasses (List::Directory in factory/List/Directory.pm and 
List::File in factory/List/File.pm), the methods are written as if they were 
being called directly, thereby ignoring the existence of a base class.

Is this the factory method, or am I deluding myself? Does anyone have any 
decent links for design patterns in Perl?

--Nigel Wetters

_
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Factory method

2001-10-18 Thread _brian_d_foy

In article [EMAIL PROTECTED], [EMAIL PROTECTED] 
wrote:

 http://www.perfascist.com/factory.tar.gz

couldn't find this domain *shrug*

 The List class is nothing but a placeholder for its subclasses. When it's 
 constructor method (sub new) is called, it creates an instance of one of its 
 subclasses, the choice of subclass being based on one of the arguments to 
 the constructor method.

 Is this the factory method, or am I deluding myself? Does anyone have any 
 decent links for design patterns in Perl?

this is a factory since it creates objects in other packages. :)
-- 
brian d foy [EMAIL PROTECTED] - Perl services for hire
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Factory method

2001-10-18 Thread Nigel Wetters

Sorry, typo:
http://www.perlfascist.com/factory.tar.gz

I've already amended the example to include some comments made by people who 
found my site despite my best efforts!

Still looking for sites that have any information about design patterns in 
perl. Anyone seen any?

--Nigel Wetters

_brian_d_foy wrote:

http://www.perfascist.com/factory.tar.gz

couldn't find this domain *shrug*


_
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]