<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Adding dynamic properties to graphic handles	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/adding-dynamic-properties-to-graphic-handles/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/adding-dynamic-properties-to-graphic-handles?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=adding-dynamic-properties-to-graphic-handles</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Wed, 17 Feb 2016 18:41:57 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>
		By: Andrew Joslin		</title>
		<link>https://undocumentedmatlab.com/articles/adding-dynamic-properties-to-graphic-handles#comment-370020</link>

		<dc:creator><![CDATA[Andrew Joslin]]></dc:creator>
		<pubDate>Wed, 17 Feb 2016 18:41:57 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6006#comment-370020</guid>

					<description><![CDATA[To extend @Yair&#039;s implementation a little bit...

1) You can overload a builtin function or sealed class (like axes), and in the overloaded function define some dynamic properties
2) To add dynamic &quot;methods&quot; which don&#039;t require empty parentheses when called, take @Yair&#039;s implementation and then also define the &quot;GetMethod&quot; parameter of that dynamic property to be the same function handle that you set the property to.

I&#039;m still learning OOP, and am very new to design patterns, but perhaps this is how to implement a decorator pattern in MATLAB, given that sealed classes cannot be subclassed?

&lt;pre lang=&quot;matlab&quot;&gt;
function ax = axes(varargin)

   % Create a builtin axes object
   ax = builtin(&#039;axes&#039;,varargin{:});

   % Add a dynamic method
   p = addprop(ax,&#039;newmethod&#039;);
   ax.newmethod = @(x)fun(ax); % Maybe there&#039;s a better way to pass the axes to an anonymous function?
   p.GetMethod = @(x)fun(ax);
   p.SetAccess = &#039;private&#039;;

   function out = fun(ax)
      % Do stuff here
   end
end
&lt;/pre&gt;

Now you can call the dynamic &quot;method&quot;, &lt;i&gt;newmethod&lt;/i&gt;, without using parentheses, and the object is passed to &lt;i&gt;newmethod&lt;/i&gt; when called, just as in a normal class method:

&lt;pre lang=&quot;matlab&quot;&gt;
a = axes;
a.newmethod;
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>To extend @Yair&#8217;s implementation a little bit&#8230;</p>
<p>1) You can overload a builtin function or sealed class (like axes), and in the overloaded function define some dynamic properties<br />
2) To add dynamic &#8220;methods&#8221; which don&#8217;t require empty parentheses when called, take @Yair&#8217;s implementation and then also define the &#8220;GetMethod&#8221; parameter of that dynamic property to be the same function handle that you set the property to.</p>
<p>I&#8217;m still learning OOP, and am very new to design patterns, but perhaps this is how to implement a decorator pattern in MATLAB, given that sealed classes cannot be subclassed?</p>
<pre lang="matlab">
function ax = axes(varargin)

   % Create a builtin axes object
   ax = builtin('axes',varargin{:});

   % Add a dynamic method
   p = addprop(ax,'newmethod');
   ax.newmethod = @(x)fun(ax); % Maybe there's a better way to pass the axes to an anonymous function?
   p.GetMethod = @(x)fun(ax);
   p.SetAccess = 'private';

   function out = fun(ax)
      % Do stuff here
   end
end
</pre>
<p>Now you can call the dynamic &#8220;method&#8221;, <i>newmethod</i>, without using parentheses, and the object is passed to <i>newmethod</i> when called, just as in a normal class method:</p>
<pre lang="matlab">
a = axes;
a.newmethod;
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Will		</title>
		<link>https://undocumentedmatlab.com/articles/adding-dynamic-properties-to-graphic-handles#comment-361401</link>

		<dc:creator><![CDATA[Will]]></dc:creator>
		<pubDate>Thu, 12 Nov 2015 17:59:11 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6006#comment-361401</guid>

					<description><![CDATA[If you&#039;re just storing something like a handle and don&#039;t have any use for OOP concepts like access attributes or property listeners, is there any particular advantage to using dynamic properties rather than &lt;b&gt;setappdata&lt;/b&gt; and &lt;b&gt;getappdata&lt;/b&gt;? It seems to me the only disadvantage of application data for this purpose is the slightly less concise means of access - but in exchange for being able to assign in one line rather than two. Is there anything else worth considering?]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re just storing something like a handle and don&#8217;t have any use for OOP concepts like access attributes or property listeners, is there any particular advantage to using dynamic properties rather than <b>setappdata</b> and <b>getappdata</b>? It seems to me the only disadvantage of application data for this purpose is the slightly less concise means of access &#8211; but in exchange for being able to assign in one line rather than two. Is there anything else worth considering?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Julien		</title>
		<link>https://undocumentedmatlab.com/articles/adding-dynamic-properties-to-graphic-handles#comment-357610</link>

		<dc:creator><![CDATA[Julien]]></dc:creator>
		<pubDate>Thu, 24 Sep 2015 20:13:36 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6006#comment-357610</guid>

					<description><![CDATA[Very interesting... But when I see your first figure with this scrollable container which contains an axes, I would like to know more! Could you briefly explain how you succeedded in adding a scrollbar to the flowcontainer? Thanks in advance!]]></description>
			<content:encoded><![CDATA[<p>Very interesting&#8230; But when I see your first figure with this scrollable container which contains an axes, I would like to know more! Could you briefly explain how you succeedded in adding a scrollbar to the flowcontainer? Thanks in advance!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yaroslav		</title>
		<link>https://undocumentedmatlab.com/articles/adding-dynamic-properties-to-graphic-handles#comment-357111</link>

		<dc:creator><![CDATA[Yaroslav]]></dc:creator>
		<pubDate>Thu, 17 Sep 2015 09:41:46 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6006#comment-357111</guid>

					<description><![CDATA[&quot;&lt;i&gt;This is probably achievable, if you have a spare few days and a masochistic state of mind.&lt;/i&gt;&quot; --- Laughed my head off about that one.  Recalling the onerous days required to rewrite the &lt;a href=&quot;http://undocumentedmatlab.com/blog/undocumented-cursorbar-object&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;graphics.cursorbar&lt;/code&gt;&lt;a&gt; object into its &lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/49612-cursorbar&quot; rel=&quot;nofollow&quot;&gt;HG2 counterpart&lt;/a&gt;, I couldn&#039;t agree more.  

Supporting @Yair&#039;s point of view, I also find the sealing of HG classes vexing. Although the &lt;code&gt;dynamicprops&lt;/code&gt; approach may suit small programs or &lt;i&gt;ad hoc&lt;/i&gt; solutions, it&#039;s not applicable for large projects or general cases.  IMHO, a proper inheritance is invaluable in this matter. Perhaps we could write a petition to TMW and ask for the seal to be broken?]]></description>
			<content:encoded><![CDATA[<p>&#8220;<i>This is probably achievable, if you have a spare few days and a masochistic state of mind.</i>&#8221; &#8212; Laughed my head off about that one.  Recalling the onerous days required to rewrite the <a href="http://undocumentedmatlab.com/blog/undocumented-cursorbar-object" rel="nofollow"><code>graphics.cursorbar</code></a><a> object into its </a><a href="http://www.mathworks.com/matlabcentral/fileexchange/49612-cursorbar" rel="nofollow">HG2 counterpart</a>, I couldn&#8217;t agree more.  </p>
<p>Supporting @Yair&#8217;s point of view, I also find the sealing of HG classes vexing. Although the <code>dynamicprops</code> approach may suit small programs or <i>ad hoc</i> solutions, it&#8217;s not applicable for large projects or general cases.  IMHO, a proper inheritance is invaluable in this matter. Perhaps we could write a petition to TMW and ask for the seal to be broken?</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
