OOP Oversold??

  • Thread starter Thread starter dancer
  • Start date Start date
John Saunders said:
You're missing my point. I consider it a bad idea to create a
getter/setter for every instance variable. Instead, properties should be
used as part of the public contract of the class. As such, they don't
necessarily have anything to do with the implementation. Just because
there's a property doesn't imply that there's an instance variable behind
it. You also can't assume that calling the getter does nothing more than
return instance data, or that a setter only sets instance data. A getter
might load data from a database if it hadn't already been loaded. A setter
might set a "dirty" flag in addition to setting a backing field.

Yet the caller doesn't need to know any of that. The question of how the
getter and setter are implemented is an implementation detail. The fact
that the getter gets something (and presumably has no visible side
effects) or that the setter sets something (presumably such that the
getter would subsequently return that same value) is all that the client
needs to know.

That's encapsulation, not an implementation detail.

Very well said!

Shelly
 
Back
Top