MATLAB Object-Oriented Programming

(Joyce) #1

workspace. For information on restoring listeners when saving objects, see “Restore
Listeners” on page 13-36.


How Is the Property Data Loaded?


When loading objects from MAT-files, the load function restores the object.



  • load creates a new object.

  • If the class ConstructOnLoad attribute is set to true, load calls the class
    constructor with no arguments. Otherwise, load does not call the class constructor.

  • load assigns the saved property values to the object properties. These assignments
    result in calls to property set methods defined by the class (except in the case of
    Dependent, Constant, or Transient properties, which are not saved or loaded).

  • load assigns the default values saved in the MAT-file to properties whose values were
    not saved because the properties were set to the default values when saved. These
    assignments result in calls to property set methods defined by the class.


MATLAB calls property set methods to ensure that property values are still valid in cases
where the class definition has changed.


For information on property set methods, see “Property Set Methods” on page 8-56.


Errors During Load


If a new version of a class removes, renames, or changes the validation for a property,
load can generate an error when attempting to set the altered or deleted property.


When an error occurs while an object is being loaded from a file, MATLAB does one of the
following:



  • If the class defines a loadobj method, MATLAB returns the saved values to the
    loadobj method in a struct.

  • If the class does not define a loadobj method, MATLAB silently ignores the errors.
    The load function reconstitutes the object with property values that do not produce
    an error.


In the struct passed to the loadobj method, the field names correspond to the
property names. The field values are the saved values for the corresponding properties.


Save and Load Process for Objects
Free download pdf