[Tutor] creating read only attributes
littledanehren at yahoo.com
Sat Nov 22 16:35:09 EST 2003
> Isn't one of the basic tenants of OO that objects
> should be like "magic black
> boxes", and their inner workng should be invisable
> to outside observers? It
> seems to me that private variables are very
> important for this reason...
I've never heard of that. I thought objects were
supposed to do things automatically, but were still
supposed to be transparent. There is no need to watch
over your programmers and make sure they don't change
the internals of an object. Someone, I'm not sure who,
said about Python's lack of private variables "We're
all consenting adults here."
> The same goes for read-only attributes..... OK, so
> we could all use lots of
> methods, but if you ask me, a whole heap od methods
> called "set_a", "set_b",
> "set_c" etc. etc. is ugly... (the pyGTK classes come
> to mind). Wouldn't it be
> nice to be able to treat these attributes as
> read-only (or write-only), and
> have them behave as normal variables, rather than
> having to wrap functions
> around them?
> - --
> Thomi Richards,
Who's suggesting using a lot of methods? I was
suggesting that you could define __setattr__ in a
class to make it so that certain attributes weren't
setable. pyGTK probably has to make all of those
functions because of a poor wrapper to C, not because
they wanted some things to be private.
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
More information about the Tutor