This page describes the reasons why accessors are generated in ERP5, and globaly the purposes of accessors.
Table of Contents
Reasons for Use Of Accessors¶
Remove acquisition problems which occur when accessing bare properties.¶
Short example using given a and b objects.
a.title = 'foo'
# This is not set because the user has not input any value,
# still it's defined as an acceptable property for object b
# in its property sheet.
#b.title = ''
wrapped_b = b.__of__(a)
wrapped_b.title # Evaluates to 'foo'
Here, getting the value of the title property on wrapped_b will produce a
different result if the user put a value in it or not: in once case it will be
the value as set on the document itself, in the other case it will be the value
as set on one of it's parents in the acquisition chain. But as accessors are
defined on objects' class, the property value won't be acquired from a parent
if it's declared as a property of the object itself:
wrapped_b.getTitle() # Evaluates to the default value defined in the property sheet
Now the result is consistent whether or not the property is set "physically" on
the object or not, without removing the advantages of acquisition.
Prevent code duplication¶
Offer casting and default values¶
Related Articles¶