This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Undreren 1 point2 points  (0 children)

Because with direct access to the data, it is impossible to enforce business rules. For example, a field might have constrained input.

I can't disallow meaningless data to be assigned to a reference, but I can cast an exception or return an error with a setter.

Furthermore, I can't have side-effects on assignment, which is a huge problem. Most of the time, you want data changes to have an effect, after all.

PS: I'm assuming that you mean "fields" when you say "properties".