|
How to specialize property behavior |
A class can override property by defining a getter method for a . A getter method must be named "get" concatenated with the ucFirst of the property name and should work with no arguments. If a getter method exists, it will always be called when the property value is retrieved. It should return the property value during under all circumstances, or null if there is no value. It may trigger errors, but only to signal programming errors. The default user interface expects no errors when it creates a new peanut and gets the values of its properties.
A peanut class can override default property behavior by defining a setter method that processes the value. A setter method must be named "set" concatenated with the ucFirst of the property name and should work with the value as the only argument. If a setter method exists, it will always be called when a property value is set. It is not expected to return a value. It may trigger errors, but only to signal programming errors. The default user interface expects no errors when it creates a new peanut and sets the values of properties that are not readOnly.
If a property of a peanut is not readOnly the peanut must validate its value and return eventual error messages when [method:pnt.PntObject.validateGetErrorString|validateGetErrorString] is called. By default only the constraints defined by the of the property are applied. If more constraints are to be applied the validateGetErrorString method should be overridden.
A peanuts class can override a properties options behavior, see how to define a property options list.
The and methods should not be overridden. They delegate to the and are bypassed by the framework (it calls the propertyDescriptor directly) to for better performance and error handling. It is OK for application code to do the same (making it perform better but less readable). Application code may also call getter, setter and options getter methods directly if they will certainly be there (even better performance, well readable). However, if you decide to do this you should always check for references before you remove such a method.
Default property behavior can also be overridden by using custom subclasses of PntPropertyDescriptor or one of its subclasses. These subclasses can be instantiated from the initPropertyDescriptors method on the peanut class, or you can create and call your own variants of addFieldProp etc. To see how to instantiate a PntPropertyDesriptor subclass and register the new instance, .
Some property behavior is delegated to a classDescriptor. To override that you can create your own PntClassDescriptor subclass. The framework will instantiate this class if you override a method getClassDescriptorClass on the peanut class.
|
|