Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^4: RFR: Inside-out classes - a Class::InsideOut primer

by xdg (Monsignor)
on Mar 16, 2007 at 15:30 UTC ( #605172=note: print w/ replies, xml ) Need Help??


in reply to Re^3: RFR: Inside-out classes - a Class::InsideOut primer
in thread RFR: Inside-out classes - a Class::InsideOut primer

OI would guess that people who want private and read-only attributes are just used to "strict" languages.

I would agree more if you were talking about private vs. protected properties -- i.e. access controls from other classes.

(N.B. I avoid the term "attributes" since we also have attributes in Perl. I think it's unfortunate that some inside-out class generators talk about object "attributes" and then use attributes for methods as well.)

I think that generating accessors (and/or mutators) for every bit of state associated with an object is a mistake because it merges implementation and interface. That is the violation -- or really, repudiation -- of the principle of encapsulation. It's not about hiding data, it's about decoupling.

If you are the only one using your class, then it may not matter -- but if you share your code with others and if you want to promise some degree of API stability, then I think that making accessors for everything is a mistake. On the other hand, if you're comfortable declaring the difference between accessors you mean to be public and accessors you mean to be private in documentation and letting violators do so at their own risk, then I can see why this isn't a big deal for you.

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.


Comment on Re^4: RFR: Inside-out classes - a Class::InsideOut primer
Re^5: RFR: Inside-out classes - a Class::InsideOut primer
by Joost (Canon) on Mar 16, 2007 at 15:38 UTC
    I agree. What I meant to say is that every property that's relevant to the classes' user should have some way of getting and maybe setting it. Basically, I regard all properties as implementation details and private and they should only be exposed (via accessors) if that's useful. I certainly didn't mean that all properties should have a direct public interface. A classes' user doesn't have to know or care if a method is just a plain accessor or something else. All that matters is that the public API allows the user to do everything relevant and hide everything that's not.

Re^5: RFR: Inside-out classes - a Class::InsideOut primer
by radiantmatrix (Parson) on Mar 16, 2007 at 15:40 UTC
    I avoid the term "attributes" since we also have attributes in Perl. I think it's unfortunate that some inside-out class generators talk about object "attributes" and then use attributes for methods as well.

    And that is an excellent point. I've been considering a slight rewrite, and I think introducing the term "properties" and using it throughout is the straw that pushes me over. I'll be spending some time on that in the next week or so (hopefully).

    <radiant.matrix>
    Ramblings and references
    The Code that can be seen is not the true Code
    I haven't found a problem yet that can't be solved by a well-placed trebuchet

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://605172]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (18)
As of 2014-09-16 13:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (24 votes), past polls