This was a getter/setter example, good OO does not use such methods, as it is truly "object oriented".

I must not understand your point. Almost every object ive ever used has properties. In fact this comment is so crazy to me I cant even think of what to say in response.

An object DOES something, you don't manipulate it's properties directly (and that's what getters/setters do, just in a PC way).

Well i dont know where you get this from, it doesnt match up with my experience at all (to say the least). An object is just an encapsulation of data and the methods that manipulate that data. Its like a record that is smart enough to know what subroutines can manipulate it. Property accessors just provide a convenient syntactic sugar for how to pass data into the object and a place to validate it when you have.

Lets bring this back to one of the original uses of OO: representing graphical elements in a GUI. Now say we have a cursor object, how do we change its color without using a property accessor? IME it would normally be done by something like:

$cursor->color(BLUE);

And no, im not going to give you a non getter/setter example, as that is what this thread is all about.

---
demerphq


In reply to Re^6: Assignable Subroutines by demerphq
in thread Assignable Subroutines by dragonchild

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.