ERP5 KM

Accessors

This page describes the reasons why accessors are generated in ERP5, and globaly the purposes of accessors.

Accessors are a way to:

  • Remove acquisition problems which occur when accessing bare properties
    • Short example using given a and b objects.

         1 a.title = 'foo'
         2 # This is not set because the user has not input any value,
         3 # still it's defined as an acceptable property for object b
         4 # in its property sheet.
         5 #b.title = ''
         6 wrapped_b = b.__of__(a)
         7 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:

         1 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
    • (to complete)

  • Offer casting and default values
    • (to complete)

(to complete)

Accessors (last edited 2008-01-03 13:48:04 by localhost)

Page
  • Immutable Page
  • Info
  • Attachments
User
Learn about new ERP5 releases,technical articles, events and more.

Subscribe to the monthly ERP5 Newsletter!