in reply to Re: Make your classes use their own methods
in thread Make your classes use their own methods
"I would make the stronger statement: No attribute shall be accessed except via a get/set method"
I agree with this one, and it should actually be extended to cover access from within the class itself. That's actually the point the original post is trying to make.
"that access should itself be limited to within the class in the vast majority of cases"
I disagree with this. If I understand this correctly, you mean that those getters and setters shall not be used by other classes. This is way too general. We are not making black boxes. In fact:
There is a very subtle difference here, some attributes are real attributes that descibe the characteristics of the class, in this sense, the meaning of attribute matches its real world meaning. The setters/getters of those attributes shall be publicly accessable (although the variable represents the attribute shall be private), so that other classes instantiating this class, can understand it, measure it, observe it.
There is another type of "attributes", which are really just global variables within the class itself (most of the time, introduced by the programming of the class, but not the class itself), and no other class actually need to know them, then not just the variable itself, but its getter/setter shall be private.
Also, getter and setter of the same attribute could have different access level. Some of the attributes could be readable, but not writable from outside, so their getters are public, but setters are private.
Also, in some languages, for example Java, there is a protect access level in between private and public, so that some methods (obviously including setters/getters) are only accessible from certain classes, but not all classes. That makes a lot sense to me.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Make your classes use their own methods
by Anonymous Monk on Nov 24, 2003 at 04:45 UTC | |
by pg (Canon) on Nov 24, 2003 at 05:00 UTC | |
by Anonymous Monk on Nov 24, 2003 at 05:09 UTC |