MATLAB Object-Oriented Programming

(Joyce) #1
Error setting property 'Value' of class 'ValueProp':
Invalid data type. Value must be double or be convertible to double.

This statement attempts to assign a 1-by-2 double array to the property. This assignment
violates the size validation.

a.Value = [10 20];

Error setting property 'Value' of class 'ValueProp':
Size of value must be scalar.

This statement attempts to assign a scalar double to the property. This assignment fails
the function validation, which requires a nonnegative number.

a.Value = -10;

Error setting property 'Value' of class 'ValueProp':
Value must be nonnegative.

The validation process ends with the first error encountered.

Abstract Property Validation


You can define property validation for abstract properties. The validation applies to all
subclasses that implement the property. However, subclasses cannot use any validation on
their implementation of the property. When inheriting validation for a property from
multiple classes, only a single Abstract property in one superclass can define the
validation. None of the superclasses can define the property as nonAbstract.

Objects Not Updated When Changing Validation


If you change the property validation while objects of the class exist, MATLAB does not
attempt to apply the new validation to existing property values. However, MATLAB does
apply the new validation when you make assignments to the properties of existing
objects.

Validation During Load Operation


When saving an object to a MAT file, MATLAB saves all nondefault property values with
the object. When loading the object, MATLAB restores these property values in the newly
created object.

8 Properties — Storing Class Data

Free download pdf