The relational tool for demeter is the view. So you have
$o->thing1->thing2->thing3
and
SELECT thing2.thing3id FROM o, thing1, thing2 WHERE O.id= ? AND o.thin +g1_id = thing1.id AND thing1.thing2id = thing2.id
being replaced with
$o->thing123
and
SELECT thing123id FROM view123 WHERE o.id = ?

A view allows you to reach across relations without having to explicitly traverse them. It's a bit different to a stored procedure in that it's easier to express and the DB understands what it does on a deeper level and is able to think about it and optimise. In most OO systems thing123 must be implemented like a stored procedure because the languages don't have a good way of expressing relationships. Once you're doing things the stored procedure way, the language no longer really understands what your doing and so it cannot be smart, it just has to follow your instructions to the letter, with the result that you are forced to write detailed instructions and more of them.

In an OO language you end up with setters and getters because the language can't look inside thing123 to see that actually it's just ->thing1->thing2->thing3 and that it could use this for both the setter and the getter. Perl is different, it has lvalue subs. Lisp goes all the way with it's handling of getters, setters and macros, if you defined thing123 properly it is automatically both a getter and a setter and will interact nicely with all the other well defined getters and setters.


In reply to Re: Law of Demeter and Class::DBI by fergal
in thread Law of Demeter and Class::DBI by hardburn

Title:
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, 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:
    & &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.