Path: news.mathworks.com!not-for-mail
From: "Titus Edelhofer" <titus.edelhofer@mathworks.de>
Newsgroups: comp.soft-sys.matlab
Subject: Re: question about value class 'setter' method
Date: Wed, 4 Nov 2009 12:15:06 +0100
Organization: The MathWorks, Inc.
Lines: 42
Message-ID: <hcrnnr$2o9$1@fred.mathworks.com>
References: <hcqv4o$kst$1@fred.mathworks.com>
NNTP-Posting-Host: ac-edelhofert.ac.mathworks.de
X-Trace: fred.mathworks.com 1257333307 2825 172.16.75.150 (4 Nov 2009 11:15:07 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 4 Nov 2009 11:15:07 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5843
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
X-RFC2646: Format=Flowed; Original
Xref: news.mathworks.com comp.soft-sys.matlab:582323



"Ian Bell" <ibell@instepsystems.com> schrieb im Newsbeitrag 
news:hcqv4o$kst$1@fred.mathworks.com...
>I am reading through the Matlab documention to understand how classes are 
>implemented.  I came across the following statement:
>
> Value Classes.   When writing methods that update an object, you must pass 
> back the updated object and use an assignment statement. For example, a 
> value class implementation of a set method for a property requires the 
> object to be returned with the new value set.
> A = set(A,'PropertyName',PropertyValue)
>
> This is odd in that it appears to be saying that an instance of the class 
> must be updated/reassigned EVERY single time a 'setter' method is called? 
> For example, assume the class 'MyClass' has a property named 
> 'MyStringProperty' and the method 'setMyStringProperty' which updates this 
> property:
>    mc = MyClass();
>    mc = mc.setMyStringProperty( '111' );
>    mc.setMyStringProperty( '222' );
>
> I come from a C++ background and expect "MyStringProperty' to be set to 
> '222'.   The Matlab documentation implies that correct value would be 
> '111'.    Can someone clarify how I would expect to call a 'setter' 
> method.
>
> Thanks,
>
> Ian
>

Hi Ian,

yes, that is right.
 mc = mc.setMyStringProperty( '111' ); % this really sets the property
 mc.setMyStringProperty( '222' );  % this does not
This behaviour is due to being a Value Class. If MyClass was a handle class, 
the second would be sufficient.

Titus