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:
my $db = Blah::DB->new(
database => 'blahDB',
user => 'scott',
password => 'p455w0rd'
);
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?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.