Is defining get/set methods for every field overkill?
thebluepandabear
therealbluepandabear at protonmail.com
Sat Nov 19 04:19:01 UTC 2022
>
> oh. so i get it now. you have to refactor your class (change
> member variable names and also do it in all places where they
> are used througout the class. then add new methods, overloading
> them in this way and that way, all because you're initial
> design never factored in the possibility of change (or even
> some validation of the vale being returned to the client, or
> validation of value coming from the client).
>
> after 10 years of doing all that, you may well come to the
> conclusion that public member variables are not such a great
> idea afterall ;-)
These days with modern IDEs it takes a second to change the name
of a variable globally. In production level code, it may take
more time, but I doubt by a lot.
Think about it, if you have a class with 20 different variables
that don't need any special rules to access, think about the
amount of code you would have to add for getters/setters. Now in
production level code you will have thousands of these classes,
and as such you will have a good chunk of code that is
practically useless and doing nothing.
More information about the Digitalmars-d-learn
mailing list