|Problems? Is your data what you think it is?|
OO, inheriting functions from other packagesby sschneid (Deacon)
|on Jul 22, 2004 at 15:49 UTC||Need Help??|
sschneid has asked for the
wisdom of the Perl Monks concerning the following question:
This is an OO-based question that I've struggled with ever since I decided to dive into the OO-world, and still haven't really figured out. Maybe one of you can help my understanding.
The basic set-up is as follows:
Say I have three classes, Blah, Blah::DB, and Blah::Project:
Blah: this is the main program.
Blah::DB: contains all sorts of common functions I use to retrieve 'stuff' from a database.
Blah::Project: contains functions that I use to deal with 'projects'.
In Blah.pm, I'm doing the following:
Which is peachy, because now I can do things like $db->tablelist(); and whatnot.
The problem is: can I inherit the functions I use in Blah::DB into my Blah::Project package? Maybe all of my 'projects' are stored in a database, and I want to retrieve them and them store them in a 'project' object. I can't figure out a way to use any of the Blah::DB functions, however, without either:
a) creating a new Blah::DB object from within Blah::Project, or
b) pass my Blah::DB object to Blah::Project when I create a Blah::Project object (my $proj = Blah::Project->new($db);).
Neither of these seem elegant.
Can someone point me in the right direction?