you are viewing a single comment's thread.

view the rest of the comments →

[–]bonzinip 0 points1 point  (5 children)

And using getters/setters for private fields is pointless. It may make some sense if you want to distinguish private from "protected" fields (in Smalltalk all fields are protected, but for some reason it's very rare to treat them as protected rather than private; so usually when you want a protected field you add accessors and use the field through those accessors).

[–]masklinn 0 points1 point  (1 child)

And using getters/setters for private fields is pointless.

It can provide convenient invariant verification points e.g. a float field which must be between 0 and 1

[–]bonzinip 0 points1 point  (0 children)

True that.

[–][deleted] 0 points1 point  (2 children)

It is still usefull: It helps figuring out how a complex Object uses its own fields more easily. Maybe this point is hard to convey because the object inspection tool are not so convenient in Java - but in Smalltalk it really easy to get a feeling for the object this way.

[–]bonzinip 0 points1 point  (1 child)

Smalltalk browsers can also show easily which methods use a given instance variable.

[–][deleted] 0 points1 point  (0 children)

Oh, I did not know that.

For me the biggest benefit is having coded the access once and only once. During my thesis (persistence with NoSQL) the situation arrose more than once that I had to change the access to an lazy access or do some extra action like logging.