|
|
|
|
|
by masklinn
5265 days ago
|
|
> The mere act of adding a getter violates immutability. Uh what? No it does not. Writing stupid getters (or classes) might, but writing getters does not "violate immutability". Naturally, getters are not of much use if all your fields are final and hold immutable objects, but the latter can be tricky in many OO languages. Getters significantly improve the situation there, by providing a point at which you can clone your internal state and return a copy, letting you keep your object immutable even if you have mutable fields (of course this assumes you can deeply copy all your mutable member objects) |
|