|
Posted by Jerry Stuckle on 12/04/06 13:20
Curtis wrote:
>>Hi, Curtis,
>
>
> Hello :)
>
> <snip>
>
>>If these variables are public, you can never change them. But what
>>happens if you need to - i.e. for performance? Or accuracy?
>
> <snip>
>
>>Rather, if you encapsulate the longitude and latitude, making them
>>private, with accessor functions, the data is not hidden - but the
>>implementation is.
>
>
> I see, I see. All of a sudden, it's like a light bulb turned on in my
> head. I have have experience using OOP in PHP, Perl, JavaScript, and
> very little in Python and C++, but I am nowhere near an expert,
> although I have learned a lot from just trying out code and reading
> documentation. There is a lot to OOP I have yet to learn, so I'll try
> getting the materials by the experts mentioned. ;)
>
> Just to make sure I interpreted your post correctly:
>
> The benefit of encapsulation is doing things like making certain class
> members private, and then utilizing setters/getters so that you can be
> much more flexible in changing your class in the future.
>
Curtis,
Definitely. What you're doing is hiding the implementation of the class
- that is, how the data is stored. The data is still available, via the
accessor functions. But the rest of your program is not dependent on
the internal representation of that data.
Once you've released the class, you can't change or remove anything
that's defined as public (other than to add more to the public
interface). That's because you have no way of knowing who is using it.
You are, however, completely free to change anything declared as
private - because only the class itself can access those items.
The more complex the class, the more important this is. For instance,
there may be a change in the program requirements which necessitates a
change in the data for one reason or another. Or, perhaps there was a
bug in the class itself, and you need to change the data. Or any of a
million different possibilities.
Keeping the data encapsulated ensures any changes to the data only
affect the class itself, and nothing which uses the class.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[Back to original message]
|