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]