Driver Based Object Creation - string vs class
scottp at dd.com.au
Thu Jul 11 22:44:54 CDT 2002
I started a thread of conversation at the pub around how to do driver
based object creation.
I am sure that you have all used or at least heard of DBI, our favorite
database interface module.
The way you currently create a database handle with DBI is to do the
my $dbh = DBI->connect('dbi:Pg:database=fred', ...);
But the designers could easily have done the following...
my $dbh = DBI::Drv::Pg->connect(database => 'fred', ...);
So I started talking about where you would used each of these
We came up with the basic following guidelines.
1) Use String Based
. Configuration file storage of a driver
. User input for driver
. Customisation depending on platform (eg: Windows vs Linux vs
. Command line input
2) Use Class Based
. Choosing a driver that does not change except with code changes
So we came up with some examples....
1) String Based
The following examples should allow you to write code that works
with any of the drivers supported by the infrastructure
. Database (type as well as name and host etc)
= If you are careful you can construct most your code to be DB
(where you can't you should consider using DBIx::Abstract or
= You write a script to delete mail based on some strange
criteria, and you
need to choose which folder type (Mh, MBox, MailDir, POP,
IMAP, WebDAV ...)
2) Class Based
The following examples would probably require code changes to
change the driver and therefore it is ok to use class based.
. Net::Server:: Personality choices
= You write a preforked server which blocks when processing a
= Using TCP sockets vs Unix Domain Socks etc
often this will change the way you deal with things (not
much mind you)
I am presenting this to you to: get some feedback if you want; to
present the conclusions we came up with on Wednesday.
Welcome to the Digital Dimension
scottp at dd.com.au
Dismaimer: Contents of this mail and signature are bound to change
randomly. Whilst every attempt has been made to control said randomness,
the author wishes to remain blameless for the number of eggs that damn
chicken laid. Oh and I don't want to hear about butterflies either.
More information about the Melbourne-pm