Definition of "property"

Barry Scott barry at barrys-emacs.org
Sun May 30 14:29:15 EDT 2021



> On 30 May 2021, at 17:57, Irv Kalb <Irv at furrypants.com> wrote:
> 
> I am doing some writing (for an upcoming book on OOP), and I'm a little stuck.  
> 
> I understand what a "property" is, how it is used and the benefits, but apparently my explanation hasn't made the light bulb go on for my editor.  The editor is asking for a definition of property.  I've looked at many articles on line and a number of books, and I haven't found an appropriate one yet.
> 
> I have written some good examples of how it works, but I agree that a definition up front would be helpful.  I have tried a number of times, but my attempts to define it have not been clear.  Perhaps the best I've found so far is from the Python documentation:  
> 
> A property object has getter, setter, and deleter methods usable as decorators that create a copy of the property with the corresponding accessor function set to the decorated function. 
> 
> But I'm hoping that someone here can give me a more concise (one or two sentence) definition of the word "property".   
> 
> (I would like to avoid going through the whole derivation with the property function, as that would distract from the points that I am trying to make.) 

How does this sound?

An object is the combination of behaviour and state.

Classes define the object.
Methods allow the control of behaviour.
Properties hold the state.

The use of getter functions allows a property's value to be calculated.
The use of setting functions allows a property change to update the state an object.

The python property mechanism allows the getting and setter to be hidden from
the API as that the user of the object can see the propery as a simple attribute of
an object.

Barry



> 
> Thanks in advance,
> 
> Irv
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 



More information about the Python-list mailing list