http://www.perlmonks.org?node_id=220569


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.

Abigail