Quote:Original post by wild_pointer
Quote:Original post by Dmytry
Well, in practically all cases of use of getters and setters that only get and set value (but do nothing else), them is used only because "this way i place variable that is de-facto public into 'private' and so i can pretend that i'm are encapsulating something".
The use of accessors/mutators has nothing to do with encapsulation. They can break encapsulation if used sloppily. Public data doesn't even necessarily violate encapsulation though it's bad for other reasons (reasons accessors/mutators and properties exist).
my point is that usually get and set is used to achieve nice warm feeling of encapsulation, whereas it practically doesn't encapsulate anything. Like in OP's code.
Or like GetX GetY GetZ SetX SetY SetZ in 3d vector. Totally useless. Doesn't encapsulate anything at all. In case of vector, it isn't bad though as having x,y,z it is part of what we want from 3D vectors... "encapsulating" x,y,z it's like placing dot product and cross product in the private.
Some people learn how to write well-designed code(with encapsulation where necessary and everything), some people learn how to pretend for themselves that they're writing well designed code (with encapsulation and everything), and it is usually achieved by mimicking little details but not large details, or not seeing trees for forest. So they must unlearn what they have learned if they want to really do it. It's same with any other learning.
IMO _ideally_ code "inside" the class should deal with low level concepts and provide higher level concept(s), and code outside should deal with said higher hevel concept(s). The get and set doesn't give much higher level concept than just variable.
[Edited by - Dmytry on December 30, 2005 9:05:51 AM]