[Tutor] Design - getFoo and setFoo methods
Alexandre Ratti
alex@gabuzomeu.net
Thu, 16 May 2002 11:29:10 +0200
Hello,
When do you use getFoo() and setFoo() methods in your classes? (I think
there can be called "accessors"?).
The question came up on c.l.py a couple of days ago and most participants
said they did not usually use them, eg. they access attributes directly.
=> Do you only use get and set methods when data needs some extra work
before it can be stored or returned?
=> If yes, do you use the _ convention in attribute names to remember when
attributes can be accessed directly? Eg. self.foo can be read and written
directly, but self._foo should not.
So far I used many set and get methods, but now I wonder whether they
really make sense when data is not somehow transformed before
storing/returning.
Thanks again.
Alexandre