Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
|
|
question about value class 'setter' method
Posted:
Nov 3, 2009 11:15 PM
|
|
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
|
|
|
|