Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
A table is not a class, a row is not an instance, and a column is not an attribute.


We've begun using Class::DBI as a layer over the database, but clearly the CDBI is a "storage object", not an "idealized object" (just made up those labels).

Say we have a Zoo, full of Exhibits and Animals and Vets and so forth. We tend to divvy up our tables into logical groups across multiple databases (ease of backup, replication, etc), vs. having every table in the same database. So we might have tables of

Animal.animal, Animal.Medical, Animal.Feeds, Animal.MammalDetail
And in CDBI, the objects corresponding to the tables would be  Animal::Animal, Animal::Medical, Animal::Feeds, Animal::MammalDetail, etc.

So we might have a class Animal (subclassed into Mammal, Reptile whatever), which represents the OO concept of an animal, with corresponding data and methods

$a=Animal->new(%attribs); $a->feed(%feedinfo); $a->medical_checkup(%careinfo);
And there's also the "storage object" class  Animal::Animal, which is just a nice CDBI wrapper around the table Animal.Animal.

We don't force methods onto the "storage objects" (except database-esque methods), and we allow the "idealized objects" to create, hold, and use "store objects" internally to manage their persistence and interaction with the greater system.

So yes, an class isn't a table and a row isn't an instance, but in CDBI-world they are, which is useful and fine. Just don't then try to cram your application-logic into that tiny space, for it is too small and won't fit. Let CDBI or whatever encapsulate the database (highly recommended), then use that encapsulation within a higher "idealized object" that models something meaningful.

Perhaps this ramble makes sense to someone else besides myself... Great thread, dragonchild. Thanks.


In reply to Re: OO concepts and relational databases by water
in thread OO concepts and relational databases by dragonchild

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

  • 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, 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (3)
    As of 2015-11-26 18:18 GMT
    Find Nodes?
      Voting Booth?

      What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

      Results (705 votes), past polls