From: Brad Phelan <bradphelan@xtargets.com>
Path: news.mathworks.com!newsfeed-00.mathworks.com!webx
Newsgroups: comp.soft-sys.matlab
Subject: Re: Nested functions and oop
Message-ID: <10031109B76C1E484F25916E18794767@in.webx.raydaftYaTP>
Date: Fri, 24 Feb 2006 05:05:33 -0500
References: <ef2a03b.-1@webx.raydaftYaTP> <1140772064.500859.38240@e56g2000cwe.googlegroups.com>
Lines: 63
NNTP-Posting-Host: 195.230.58.11
User-Agent: Thunderbird 1.5 (Windows/20051201)
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
Xref: news.mathworks.com comp.soft-sys.matlab:332846



David Mackenzie wrote:
> Philippe Maincon schrieb:
> 
> <snip> wonderfully clear insight... <snip>
> 
> Philippe,
> although I can't answer your questions I'd like to thank you for
> posting this - I haven't been very active in MATLAB recently and it
> wasn't at all clear to me from the descriptions of nested functions
> floating around that this is possible.  A couple of years ago I
> struggled bravely with MATLAB objects (in an attempt to build a graphic
> user object toolbox, a central aim of which was to implement something
> similar to what in Version 7 appeared as uipanel objects) but wasn't
> really happy with the results, the main problem being that assignment
> of the object was necessary if attributes were to be updated - very
> ugly.  In order to avoid using global variables I had to use existing
> graphic objects to store attributes.  In contrast, your solution allows
> proper instantiation of objects!
> 
> For example, if you change the increment function to allow a couple of
> dummy parameters:
>     function increment(obj,event)
> and define a pushbutton from the command line:
>     uicontrol('style','pushbutton','callback',c.increment)
> this works fine when you click the button.  However, I never found a
> good way to do this with MATLAB objects without using global variables
> (admittedly I wasn't familiar with function handles at that time).
> 
> Maybe someone else knew this already, but I've never seen it explained.
>  Somehow this important feature wasn't highlighted in the release
> notes.  I think your insight is certainly worthy of the File Exchange.
> 
> Best regards,
> David Mackenzie
> 

I've been using the above techniques for object oriented programming in 
Matlab for a while now. See the below snippets on my website for some 
tutorials.

http://xtargets.com/snippets/posts/show/39
http://xtargets.com/snippets/posts/show/42

Nested functions can be used to build object oriented frameworks but 
that is merely a side effect. They are usefull in their own right. If 
you want to get technical then yes objects and nested functions are
dual concepts.

An object is data with a set of nested functions attached.
A nested function is a function with some data attached.

Mathworks could build a proper OO framework around nested functions I 
guess but I don't believe they will.

Brad