in reply to Re: Accessor methods again.
in thread Accessor methods again.

Howdy!

I think what you meant to say was "it runs counter to encapsulation...".

If you need to extract values from an object, you need a method. If you always use a method to fetch data from an object, you have no way of knowing (and no need to know) whether you are fetching an attribute or a computed value. Encapsulation means, among other things, that you have no need to know the distinction. The object makes certain data available to you via a well defined API, to wit, the methods frequently labeled "accessors".

yours,
Michael

Replies are listed 'Best First'.
Re^3: Accessor methods again.
by gam3 (Curate) on Oct 07, 2005 at 05:40 UTC
    This is a very good point. I think it makes it clear that an object attributes should really each have a method. And the only time you would want to have something like a get/set method would be if the object is something like a bookshelf where you will be adding and removing arbitrary objects.

    Thanks for helping me think about this.

    -- gam3
    A picture is worth a thousand words, but takes 200K.