Contributed by lattice
on Nov 15, 2000 at 05:41 UTC
> object-oriented programming
I'm trying to implement a DBI-like module that handles input and output in a generic manner.
I want to be able to take input from a hash, a database, freezethaw, xml, or whatever, then output it
using html, xml, text, etc.
The method calls would ideally take the following form:
$myObj = Obj->connect( $source, @additionalArgs );
$myObj->set_output( 'html' );
or something very similar. (the 'connect' method could be replaced with anything, but it's familiar since DBI's pretty well known)
The way I have the object model physically structured is as follows:
| +-- DB
| +-- XML
| +-- Hash
| +-- etc.
Now, the crux of the problem is that I don't want the programmer using this module to have to worry about creating a new Obj::Input::XML object. I want that to be part of the calling syntax, ala Tim.
I have the output portion running fine, using the $myObj->set_output( $type ) method. Would it be Kosher to use a $myObj->set_input( $type ) method to hack the symbol table so that $myObj->input points to the appropriate place, or
is something like DBI's method relatively easily implementable WITHOUT using XS or anything too fancy? This module is relatively lightweight (outside of its extensive use of object orientation), and I don't want to make it any bigger than necessary.
Also, I'm having some trouble deciding when to use inheritance, since it's rather a strange situation.
Should MyObj by in MyObj::Input::*'s @ISA, or should the Input::* classes inherit from a generic MyObj::Input class that doesn't inherit from MyObj?
I'm rather confused, since MyObj::Input::* is used
by MyObj, rather than a subclass of MyObj.
Any help to smooth my very confused line of thought would be MUCH appreciated.
|Answer: Class Hierarchy Design|
contributed by tye
Please post this to Seekers of Perl Wisdom and surround your code and/or "ASCI art" in <code></code> tags so it shows up correctly.
The Q&A section is for FAQ-like questions. Hence the request that you try to avoid using a description. If you can't adequately describe your question in the subject line, then you probably should be posting to Seekers of Perl Wisdom.
|Answer: Class Hierarchy Design|
contributed by metaperl
A lot of what you want is available in Lincoln Stein's Boulder.
Additionally take a look at Alzabo and the DBIx hierarchy on CPAN before commencing your coding to avoid feature duplication.
Please (register and) log in if you wish to add an answer
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
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:
Outside of code tags, you may need to use entities for some characters:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||