Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I've recently been writing Perl objects until they come out of my ears. This has meant a great deal of re-reading of Mr Conways book, and a lot of soul-searching as to which aspects to keep and which are over-engineering for the requirements and the platform.

Since Perl's implementation of OO is commonly used with a hash, one hash for a class and all it's 'parents'. To avoid collision between names of inherited attributes a namespace is defined for each package and prepended to the attributes of an object. This is a poor summary of section 6.2.6 of OO Perl by Damian Donway.

Well it set me to thinking, that since I was brought up believing all properties of an object should be viewed through accessor methods, and altered through mutator methods, one way of achieving this was to slap on a long namespace to stop people tampering, it seemed a little more dictatorial than the '_' affordance, although I stuck to that too.

$object->{_id}; $object->{_private_property_of_template_called_id_leave_it_be}; # Both could then have an accessor method, respectively sub get_id () { $_[0]->{_id} } sub get_id () { $_[0]->{ _private_property_of_template_called_id_leave +_it_be } } # And each would be called $object->get_id();

My reasoning being, the the major reason for people using the properties rather than the accessors, which might perform other duties, was mis-placed laziness.

Obviously, I hope, you can see that I've exagerated the length of the property, but does this makes sense to use? I really am in two minds as to whether this is a good thing, so I thought I'd post it here as people have some pretty strong views on OO...

--

Brother Frankus.

¤


In reply to A new take on affordance. by frankus

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!
  • 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?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (10)
    As of 2015-07-30 07:43 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (270 votes), past polls