33 ms·
Getters and setters do more than just type enforcement. In specific they allow for encapsulation where users of the class shouldn't be concerned with how things
by ddtaylor 7y ago
Getters and setters do more than just type enforcement. In specific they allow for encapsulation where users of the class shouldn't be concerned with how things are implemented. There may be complex relationships of members that needs to be maintained and by not using a method to do the "set" operations you are either tasking every consumer of the object with that burden or you are making it impossible to change those relationships later without breaking them.