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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I'd certainly wouldn't use constructors to set attributes. If you do that, it becomes harder to do inheritance. How would you do multiple inheritance if your contructors set attributes? Suppose you inherit two classes, and the constructors of both classes set attributes. At least one of the constructors will work will not have the right reference to work with.

I also shy away from using lvalued accessors. They are great for examples, as they don't take much space (screen space is a commodity when presenting), but they are awkward in practise. You can't easily intercept the passed in value, so masking such a method is hard.

You don't have to have set_x, get_x accessors - a common way is to have a single accessors that sets an attribute if it gets an argument, and gets it if there isn't one.

But I'm not a big users of accessors. For me, objects are more than a bunch of values with a ribbon around them. If I want just a bunch of attributes, I'd use something struct-like - for instance, a hash. For me, an object is a thing that keeps state. Attributes are used to record the state; methods are used to transit from one state to another.

Abigail


In reply to Re: (my?) problem with re-blessed references(?) by Abigail-II
in thread (my?) problem with re-blessed references(?) by BrowserUk

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-25 07:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found