|
Matlab displays a M-lint and gives us a suggestion as follows:
M-Lint has identified a reference to a second property within a set method for a non-Dependent property. This practice is not recommended. When MATLAB loads an object, you have no control over the order in which it sets properties. If the second property is not set when your code expects it, the reference to the second property fails.
See “Avoiding Property Initialization Order Dependency” for ways to accomplish this task. For example, you can make a property Dependent and have it reference a new, private property that you load and save without referencing other properties.
Although you can suppress this message, as described in “Suppressing M-Lint Indicators and Messages”, that practice is not a recommended. Others might attempt to save and reload objects from this class and see errors or get unpredictable results.
I think it is not a good solution, MATLAB should publish the order in which it sets properties when loading an objects, since it is useful for a reference to a second property within a set method for a non-Dependent property.
For example, 'clAb' and 'dNoRows' are properties of a class,
function set.clAb(oObj,tValue)
oObj.clAb = tValue;
oObj.dNoRows = length(tValue);
end
It is not convient to code the function mentioned above through event 'Postset'.
It is consume more time to code as the suggestion mentioned as Matlab.
|