in reply to Beginner OOP style question

Your database is a persistent collection of Persons. It is not a Person, but it needs knowlege of a Person's data. One stylish way to do that is to name its columns after a Person's accessor methods. A Person constructor can be designed to initialize directly from a single record in the database. Example:

my $gnsth = $dbi->prepare $sqlthing; my @bettys = map {Person->new($_)} @{$gnsth->fetchall_arrayref('Elizabeth')};
which obtains an array of potential Betty Persons from an SQL statement with knowlege of what data array can construct a Person, and a single placeholder for given neames. The OOP model is that the database is a persistent store of a collection of Person objects.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Beginner OOP style question
by thpfft (Chaplain) on Mar 02, 2002 at 16:47 UTC

    ...and Class::DBI may just end up doing all your work for you if you take to the poop approach.

    wonderful, wonderful module. Well, modules: you do have to install a lot of the Schwern back catalogue. It has a few quirks, naturally, but an increasingly devoted following.

    All you have to do is write a six or eight line subclass for each of your categories of object - in which you mention the names of the table, the columns and the key, and describe any relationships with other tables - and you have your application. Or a big part of it, at least.

    It works particularly well sat between template toolkit and mysql, by the way, leaving a site designer able to hook objects directly out of the database at will.

    sorry about the evangelical outburst.