Quote:
Originally Posted by jjshabado
Indeed.
fair enough. i'll have to poll some of my colleagues about the cost vs value of encapsulation and private variables. we're a c++ shop though, so "doing stuff so that the compiler can tell you before you shoot yourself in the face" has a higher value than it might in other languages.
i did think of a use case for your private setter example, though: if you're using a weakly-typed language that allows enforcement of types on method arguments, then your example is shorthand for writing this a bunch of times:
Code:
if y.instanceOf(ObjectY) {
this.x = y;
} else {
raise WrongObjectException;
}
thanks, i'm here all week. pm me for consulting rates.