[ale] Py[h]hon syntax (sic)
Michael Hirsch
mhirsch at nubridges.com
Fri Jan 28 14:40:12 EST 2005
> -----Original Message-----
> From: ale-bounces at ale.org [mailto:ale-bounces at ale.org] On Behalf Of
> Benjamin Scherrey
> Sent: Friday, January 28, 2005 11:41 AM
> To: Atlanta Linux Enthusiasts
> Subject: Re: [ale] Py[h]hon syntax (sic)
>
> Michael,
>
> Actually python does have a mechanism, albeit a big odd, for
making
> data private but it is not standard python practice to use
getter/setter
> methods. Indeed, its generally poor practice in most languages but I
see
> a lot of poorly written C++ & Java strewn with it. There is the
> occasional need for these accessors in some languages but python has
> gone even further and completely eliminated their need by explicit
> support for properties. Properties allows your class users to use
syntax
> just like they were accessing the data members directly but actually
> routes the access through methods in the class that validate,
> manipulate, or generally enforce the interface to that data. Indeed,
> through this method one can define read-only (and write-only!)
> properties giving your data further protection. This provides for
better
> enforcement of encapsulation whereas in most cases where you see
> getter/setter methods, you've actually identified a violation of
> encapsulation and poor design.
<google_search ... read .. >
Wow, that's pretty cool. Is there a way to do it where you don't have
to write the getter/setter? So, if I'd like to have a variable exposed
to read and write I don't need to do anything because by default
everything is available outside the class. But if I want a read only
member, I need to setup a reader methods and declare it. What I'd
really like is declare a member read only, but not have to write
accessor methods unless they are needed. I didn't see that mentioned in
any of the docs. Did I miss it?
Thanks,
Michael
More information about the Ale
mailing list