+2  A: 

Protection. Some properties/methods shouldn't be called from without the class...ever. I'm sure you maintain the sole authority to tell anybody your social security number, right? They have to ask you (getter)? Certainly you wouldn't advise we allow people direct access to private data/methods in our own lifes...why treat your applications any different? :)

Jonathan Sampson
So...if I'm understanding the gist of this...getters and setters for OO languages that don't have a method to hide their namespace?
Avery Payne
They build a brick wall around your class, which specific rights to certain items on the inside. Some classes have properties that should not be handled by anybody, ever. These would be defined as private or protected, and as such nobody could manipulate their values from outside of the class. Only by providing a getter can they actually tell what the value is, and only by providing a setter can they actually manipulate the value. You are King of your data - and the only access people have to the inside, is the access you grant them.
Jonathan Sampson
Interesting, more so for the psychology of that explanation than for the explanation itself. I sense another question coming on...but judging on how well the search-for-duplicate-questions feature works (just got closed in less than 30 minutes), I'll have to phrase it carefully. In any case, thanks for the clarification!
Avery Payne
Good luck :) Hope you find the clarity you seek soon :)
Jonathan Sampson
+1  A: 

One way that I've found it to be helpful is to be able to set a breakpoint on the set (more so than the get). That probably means "I'm coding it wrong," but at least I can find out exactly when it changes.

Mark Rushakoff
Actually, I can tell you that it's a function of your debugger. Your debugger (or language, or the engine that drives the language if it's interpretive/semi-compiled/p-code) does not support breaking on the state-change of a property (variable), and you are therefore forced to emulate this behavior. I've been in different languages that do and do-not support this feature, and while it's nice to have, it's not a show-stopper. Still, +1 for (a) at least realizing it's a limitation (b) finding a way around it (c) pointing out a practical use for it, even if it's not a direct answer.
Avery Payne
+3  A: 

Here is Allen Holub (who is brilliant) on the matter. He goes into much more detail on this subject in Holub on Patterns. Some things require public getters and setters like serialization and patterns like the Data Transfer Object pattern. In general, I think necessary evil since your application becomes convoluted when you don't use them.

JP Alioto
+2  A: 

Getters and Setters hide your classes data specifics from the users of your classes.

In many cases they are not fully utilized, but it is always a good idea to use them. Direct access to your objects data reduces encapsulation.

If you don't use getters and setters, when you change your mind about a data member, you break your classes interface, and must alter the rest of your codebase to conform to the change. In some cases where your class represents part of a public API this isn't even possible. If you wrap your properties in getters and setters you can make those changes, and hide them from consuming code by modifying the getter and setter methods.

Matthew Vines
+1  A: 

Getters and Setters are one aspect of implementing the Open/Close principle. If you encapsulate all of your functionality behind proper properties then code that uses your properties won't break. It also makes it possible to completely replace that object with something else in the future -- espcially if you code to an interface instead of a class.

They are so important that C# went through the trouble to make basic getters and setters easy to write.

To further understand why some aspects of OOD is important, read the book Emergent Design by Scott Bain.

Talljoe
I'll look into the book. In the meantime, if I'm understanding this at a glance, you're implying that I really, really, don't want to expose more than what's necessary to any other objects...it sounds almost as if all objects should be very tightly encapsulated and everything transacts as if there are millions of little API calls between each object...bah, I'm getting tired, forget that comment.
Avery Payne