V
Vikram
Why do we use getter and setters if we can do the same work by
declaring the public data members.
Your answer will be appriciable.
declaring the public data members.
Your answer will be appriciable.
Vikram said:Why do we use getter and setters if we can do the same work by
declaring the public data members. Your answer will be appreciable.
Why do we use getter and setters if we can do the same work by
declaring the public data members.
Why do we use getter and setters if we can do the same work by
declaring the public data members.
Your answer will be appriciable.
Why do we use getter and setters if we can do the same work by
declaring the public data members.
To add to this, the typical question that a class designer ought to have[ SNIP ]Why do we use getter and setters if we can do the same work by
declaring the public data members.
Your answer will be appriciable.
"Getter" and "setter" are ordinarily used to refer to methods
that don't do much work: A "setter" usually stores its argument
value in a data field (perhaps with a few sanity checks and perhaps
changing a related field to maintain agreement), and a "getter"
typically just returns whatever is stored in some field. They may
remain this way -- but the fact that they are methods and that the
underlying data is hidden from outsiders gives you the freedom to
change things later, if the need arises. If you expose the data
fields, those fields' names, types, and significance all become part
of your class' API, something you can't change without risking
breakage in the code that uses your class.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.