OOP Oversold??

S

Shelly

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
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,177
Latest member
OrderGlucea
Top