Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: question about value class 'setter' method
Date: Wed, 4 Nov 2009 04:15:20 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 15
Message-ID: <hcqv4o$kst$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257308120 21405 172.30.248.37 (4 Nov 2009 04:15:20 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 4 Nov 2009 04:15:20 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1611255
Xref: news.mathworks.com comp.soft-sys.matlab:582233


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