[Tutor] properties not working in 2.2

alan.gauld@bt.com alan.gauld@bt.com
Tue, 18 Dec 2001 11:27:11 -0000

> I have observed such a feature in MS's C# as well. 
> Can some one tell from their experience if it's present in 
> other languages

Its in VB and also in Delphi.
I'm not sure which did it first but it definitely seems 
to come from the Windows world, either via MS or Borland.

In both cases it was originally used to enable 
intelligent GUI builders - you can instantiate a 
copy of the object when placing it on the form and 
set attributes via properties. The property events 
can do smart things like display live data in 
design mode etc. At least I think thats what they 
were first in vented for, my memory is getting hazy 
as old age sets in ;-/

In any case it turns out that they are more generally 
useful - for example you can define a property which 
is a derived field but looks like a fixed field:

### Pseudo code warning ###
class X:
    def __init__(self,min,max):
       self.min b= min
       self.max = max
    def getMean(self): return (self.min-self.max)/2
    property average(self.getMean,None,None, "get average")

x = X(1,5)
print x.min
print x.max
print x.average

So it looks like average is a field of X but in 
fact is a return from a method. The same could 
be done for max,min and the whole thing could 
wrap a database table such that the min,max and 
average did a dynamic SQL lookup and returned 
the relevant values. But to the client it still 
looks like an attribute of the object...

Alan g.