gnue-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUe-dev] Proposal for property access functions


From: Reinhard Mueller
Subject: [GNUe-dev] Proposal for property access functions
Date: Thu, 31 Mar 2005 23:49:18 +0200

Hi all,

as we now require Python 2.3, we can use those cool features like
property access functions.

Please let me propose to use a common naming scheme for those access
functions.

Short reminder/introduction: With Python 2.3, if you use "new style
classes" (classes derived from the "object" class), you can define
properties like the following:

class foo (object):
  def set_bar (self, value):
    self.__bar = value.lower ()
  def get_bar (self, value):
    return self.__bar
  bar = property (get_bar, set_bar)

Then, you can use bar as if it were an instance variable of foo, but any
access to bar will run over the set_bar and get_bar methods.

Now, for the sake of maintainability, readability and consistence I
suggest that we:

* use names for properties that don't begine with an underscore (i.e.
make the property "parent", not "_parent" for example)

* use a private (e.g. "__bar") but otherwise identical variable name for
instance variables hidden behind a property (e.g. "bar")

* make accessor methods private methods and name them __set_prop and
__get_prop; this makes sure they don't get mixed up with "normal"
methods that already have names like "setCurrentResultSet" or
"getRecordCount" and they are not called directly, so the difference
between an instance variable and a property remains transparent.

So, for example, a property "foo" would be implemented with the methods
__get_foo and __set_foo and act on the hidden variable __foo.

Sorry if I sound like Adrian Monk here, but I think we will use
properties like that *widely* from now on, and sticking to such a scheme
will make our life easier.

Thanks,
Reinhard

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil


reply via email to

[Prev in Thread] Current Thread [Next in Thread]