Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Problems? Is your data what you think it is?
 
PerlMonks  

Class Hierarchy Design

by lattice (Initiate)
on Nov 15, 2000 at 00:41 UTC ( [id://41694]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

lattice has asked for the wisdom of the Perl Monks concerning the following question:

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->some_operations; $myObj->set_output( 'html' ); $myObj->output;
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:

  Obj
   |
   +-- Input
   |     |
   |     +-- DB
   |     +-- XML
   |     +-- Hash
   |     +-- etc.
   |
   +-- Output
         |
         +-- HTML
         +-- XML
         +-- 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.

Replies are listed 'Best First'.
Re: Class Hierarchy Design
by tye (Sage) on Nov 15, 2000 at 00:59 UTC
    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.
Re: Class Hierarchy Design
by metaperl (Curate) on Nov 15, 2000 at 14:27 UTC
    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://41694]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.