Re: [CDBI] Different subclasses for one table / Factory Pattern?

Perrin Harkins <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.class-dbi
Message-ID <[email protected]>
On Sun, 2006-07-30 at 21:19 +0200, Stephan Brunner wrote:
> Right now, I have only one table for *all* files, but need to create different 
> File::<something> objects depending on column values (the file name, for 
> example). I want $dir->files() to return a list of objects in the 
> per-file-specific subclass. Is it possible to set this up using Class::DBI? 

You can look at Class::DBI::Relationship::ISA or you can try making
something yourself.  When I needed to do something like this, I made a
class that just had the primary key and the class name for columns and
provided a method which would fetch the correct class of object.  That
does mean extra database fetches.

- Perrin
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.