http://qs321.pair.com?node_id=398323


in reply to Perl Factory Method Pattern?

To answer the questions you actually asked, in reverse order:

What you've coded will work, and most of it is fine; but there are a couple of things I dislike about the class structure you've used:

You've said you have written a few of these; if you put the code from _init into a separate module, called, say, Factory, in a method called something like "makeOSSpecific", you can get reuse. The first parameter would be the base class name, so you'd call it from "new" something like: return Factory::makeOSSpecific( "ProcInfo", $self ). There would be no need to include Factory in the class hierarchy, you'd just require or use it in ProcInfo.