[linux-audio-dev] Re: MVC

Paul Davis paul at linuxaudiosystems.com
Mon May 12 08:42:01 UTC 2003

>Does the model keep a list of views and call back to them?
>for each view do
>	view->update(me);

definitely not. that would require the model to know something about
the view. it gets hairy because you generally can't get away with a
single "changed" method if the model has any real complexity. you have
to tell the views what has changed so that they don't have to do too
much work.

to do this properly, i believe its ideal to use some kind of anonymous
callback system so that the model can signal changes, and 0 or more
views can pick them up. its possible to do this in C, though its much
nicer in C++ with libsigc++ (or the boost signals/slots library; i'm
leaving out the Qt one because it requires a preprocessor to run over
your code first, but it could be used if you insisted on it :).

if we allow ourselves to peek inside the callback system, what is
really happening looks something like this (to use C++ syntax):

       model->changed ();

       Model::changed () {
          for each registered callback {
	        callback->execute ();

the callback system (e.g. libsigc++) takes care of managing callback
(de-) registration, lifetime management, etc. etc.


More information about the Linux-audio-dev mailing list