Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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?

-s.

In reply to OO, inheriting functions from other packages by sschneid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-18 18:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found