To provide a very blunt example (as I am at work and can't currently think of a sensible example). If I write a groovy class like this
class Wendy{
byte[] frank
String doSomethingWithFrank(){
frank = someServiceThatReturnsByteArray()
}
}
And then groovy makes me getters and setters under the hood
how is this any different to:
class Wendy{
public byte[] frank
String doSomethingWithFrank(){
frank = someServiceThatReturnsByteArray()
}
}
so if you wrote
class Jenny{
Wendy wendy = new Wendy()
void pointless(){
wendy.doSomethingWithFrank()
functionThatProcessByteArray(wendy.frank)
}
functionThatProcessByteArray(Byte[] var1){
// do something
}
}
and then a month later the someServiceThatReturnsByteArray now returns a Stream
class Wendy{
Stream susan
String doSomethingWithFrank(){
susan = someServiceThatReturnsByteArray // well used to
}
}
groovy now automatically creates getters that return Stream rather than byte[]
the class Jenny would no longer compile as it is trying to use a byte[] as it is coded against the variable declaration not the desired user interface.
This mean that the two classes are very highly coupled, which is BAD.
I believe the point of making all variables private and controlling access is that the developer of the class can change any implementation detail inside without affecting anybody on the outside, but using this system, no detail of that variable is hidden from a user of the class.