SCJP 5.0 (91%), SCBCD 1.3 (94%), SCWCD 1.4 (88%)
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Lucius Stephienn:
Hi,
I saw that many programmers use (invoke) getters and setters in the same classes that were defined.
(Let's assume that g/s dont do any operation except for assignment/return)
Is it better for code to use direct access to it's private fields rather than that ?
For egzample; there are nearby setter and direct assignment which does not have setter. When I see something like that it's confusing and I must look little more closely to understand it.
What do You think?
I won't go so far as to say that one way is ALWAYS better than another
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
But, if you don't have getters and setters (or the same thing under a different name), you must allow public access to member variables of classes in oreder to affect the state of the class, which breaks encapsulation, something which is generally frowned upon.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |