<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264897</link>
    <title>MATLAB Central Newsreader - question about value class 'setter' method</title>
    <description>Feed for thread: question about value class 'setter' method</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Wed, 04 Nov 2009 04:15:20 -0500</pubDate>
      <title>question about value class 'setter' method</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264897#691903</link>
      <author>Ian Bell</author>
      <description>I am reading through the Matlab documention to understand how classes are implemented.  I came across the following statement:&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
A = set(A,'PropertyName',PropertyValue)&lt;br&gt;
&lt;br&gt;
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:&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mc = MyClass();     &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mc = mc.setMyStringProperty( '111' );&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mc.setMyStringProperty( '222' );&lt;br&gt;
&lt;br&gt;
I come from a C++ background and expect &quot;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.&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
&lt;br&gt;
Ian</description>
    </item>
    <item>
      <pubDate>Wed, 04 Nov 2009 11:15:06 -0500</pubDate>
      <title>Re: question about value class 'setter' method</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264897#691993</link>
      <author>Titus Edelhofer</author>
      <description>&lt;br&gt;
&quot;Ian Bell&quot; &amp;lt;ibell@instepsystems.com&amp;gt; schrieb im Newsbeitrag &lt;br&gt;
news:hcqv4o$kst$1@fred.mathworks.com...&lt;br&gt;
&amp;gt;I am reading through the Matlab documention to understand how classes are &lt;br&gt;
&amp;gt;implemented.  I came across the following statement:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Value Classes.   When writing methods that update an object, you must pass &lt;br&gt;
&amp;gt; back the updated object and use an assignment statement. For example, a &lt;br&gt;
&amp;gt; value class implementation of a set method for a property requires the &lt;br&gt;
&amp;gt; object to be returned with the new value set.&lt;br&gt;
&amp;gt; A = set(A,'PropertyName',PropertyValue)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; This is odd in that it appears to be saying that an instance of the class &lt;br&gt;
&amp;gt; must be updated/reassigned EVERY single time a 'setter' method is called? &lt;br&gt;
&amp;gt; For example, assume the class 'MyClass' has a property named &lt;br&gt;
&amp;gt; 'MyStringProperty' and the method 'setMyStringProperty' which updates this &lt;br&gt;
&amp;gt; property:&lt;br&gt;
&amp;gt;    mc = MyClass();&lt;br&gt;
&amp;gt;    mc = mc.setMyStringProperty( '111' );&lt;br&gt;
&amp;gt;    mc.setMyStringProperty( '222' );&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I come from a C++ background and expect &quot;MyStringProperty' to be set to &lt;br&gt;
&amp;gt; '222'.   The Matlab documentation implies that correct value would be &lt;br&gt;
&amp;gt; '111'.    Can someone clarify how I would expect to call a 'setter' &lt;br&gt;
&amp;gt; method.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Thanks,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Ian&lt;br&gt;
&amp;gt;&lt;br&gt;
&lt;br&gt;
Hi Ian,&lt;br&gt;
&lt;br&gt;
yes, that is right.&lt;br&gt;
&amp;nbsp;mc = mc.setMyStringProperty( '111' ); % this really sets the property&lt;br&gt;
&amp;nbsp;mc.setMyStringProperty( '222' );  % this does not&lt;br&gt;
This behaviour is due to being a Value Class. If MyClass was a handle class, &lt;br&gt;
the second would be sufficient.&lt;br&gt;
&lt;br&gt;
Titus</description>
    </item>
    <item>
      <pubDate>Wed, 04 Nov 2009 14:58:45 -0500</pubDate>
      <title>Re: question about value class 'setter' method</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264897#692062</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
&quot;Ian Bell&quot; &amp;lt;ibell@instepsystems.com&amp;gt; wrote in message &lt;br&gt;
news:hcqv4o$kst$1@fred.mathworks.com...&lt;br&gt;
&amp;gt;I am reading through the Matlab documention to understand how classes are &lt;br&gt;
&amp;gt;implemented.  I came across the following statement:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Value Classes.   When writing methods that update an object, you must pass &lt;br&gt;
&amp;gt; back the updated object and use an assignment statement. For example, a &lt;br&gt;
&amp;gt; value class implementation of a set method for a property requires the &lt;br&gt;
&amp;gt; object to be returned with the new value set.&lt;br&gt;
&amp;gt; A = set(A,'PropertyName',PropertyValue)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; This is odd in that it appears to be saying that an instance of the class &lt;br&gt;
&amp;gt; must be updated/reassigned EVERY single time a 'setter' method is called?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;   For example, assume the class 'MyClass' has a property named &lt;br&gt;
&amp;gt; 'MyStringProperty' and the method 'setMyStringProperty' which updates this &lt;br&gt;
&amp;gt; property:&lt;br&gt;
&amp;gt;    mc = MyClass();&lt;br&gt;
&amp;gt;    mc = mc.setMyStringProperty( '111' );&lt;br&gt;
&amp;gt;    mc.setMyStringProperty( '222' );&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I come from a C++ background and expect &quot;MyStringProperty' to be set to &lt;br&gt;
&amp;gt; '222'.   The Matlab documentation implies that correct value would be &lt;br&gt;
&amp;gt; '111'.&lt;br&gt;
&lt;br&gt;
That depends -- is MyClass a handle class or a value class?  In the former &lt;br&gt;
case, it will be '222' -- in the latter case, '111'.&lt;br&gt;
&lt;br&gt;
&amp;gt; Can someone clarify how I would expect to call a 'setter' method.&lt;br&gt;
&lt;br&gt;
You might want to review the documentation that describes the differences &lt;br&gt;
between MATLAB object-oriented programming and C++:&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/brqzfut-1.html&quot;&gt;http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/brqzfut-1.html&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
as well as the section of the documentation that describes the differences &lt;br&gt;
between the two types of objects, handle and value objects:&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/brfylq3.html&quot;&gt;http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/brfylq3.html&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
I think the second and third sections in that first link will alleviate your &lt;br&gt;
confusion.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com&lt;br&gt;
comp.soft-sys.matlab (CSSM) FAQ: &lt;a href=&quot;http://matlabwiki.mathworks.com/MATLAB_FAQ&quot;&gt;http://matlabwiki.mathworks.com/MATLAB_FAQ&lt;/a&gt; </description>
    </item>
  </channel>
</rss>

