Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: (my?) problem with re-blessed references(?)

by Abigail-II (Bishop)
on Dec 17, 2002 at 16:23 UTC ( #220569=note: print w/replies, xml ) Need Help??

in reply to (my?) problem with re-blessed references(?)

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.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2020-09-20 20:43 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (122 votes). Check out past polls.