Thread Subject: useful reference to a second property

Subject: useful reference to a second property

From: meng long

Date: 17 Nov, 2009 08:13:01

Message: 1 of 1

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.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
set method meng long 17 Nov, 2009 03:14:07
mlint meng long 17 Nov, 2009 03:14:06
rssFeed for this Thread

Contact us at files@mathworks.com