[linux-audio-dev] MVC again

2003-06-04 Thread Juhana Sadeharju
Hello. It is still quite unclear to me how I actually would code
the MVC type software. Can anyone give practical hints?
Practical examples taken from existing software would be fine
too.

What open source software uses MVC? Most open source software
seems to manipulate the model data in the GUI routines, I see.

MVC sure is a great thing, but I would like to see a concrete
toolkit or a hint list which helps me in making perfect MVC
code immediately. Is it even possible to write a MVC toolkit?
What would be in such a toolkit?

Best regards,

Juhana


Re: [linux-audio-dev] MVC again

2003-06-04 Thread Steve Harris
On Tue, Jun 03, 2003 at 06:44:08PM +0300, Juhana Sadeharju wrote:
 MVC sure is a great thing, but I would like to see a concrete
 toolkit or a hint list which helps me in making perfect MVC
 code immediately. Is it even possible to write a MVC toolkit?
 What would be in such a toolkit?

GTK has Adjustments which are generally compatible with the MVC worldview,
you update them with a call and they sognal all the things that are
registered to them, eg. textboxes adn sliders or whatever.

The problem comes when you need something more complex than an Adjustment
can represent, then you have to roll your own code.

You can look at the state object in the jamin source if you want to see a
dodgy GPL'd implementation of the MVC pattern ;)

- Steve


Re: [linux-audio-dev] MVC again

2003-06-04 Thread Lukas Degener


MVC sure is a great thing, but I would like to see a concrete
toolkit or a hint list which helps me in making perfect MVC
code immediately. Is it even possible to write a MVC toolkit?
(...)

What would be in such a toolkit?

Depends on what the toolkit is ment to do. The most consequent use of 
mvc patterns that i saw so far is found within the JFC/Swing classes. 
(Although there View and Controller are often(or always?) the same 
object iirc. )
It's been a long time since i last did something in java, so i can't 
come up with concrete class names, but i think that for instance there 
was this Table/TableModel etc. Actualy almost any gui component within 
swing is designed as a specific view on a certain data model, even 
for simple things: You could consider the JButton as View on a JAction 
model.

So if you want concrete examples of this and other  design patterns, 
this might be interesting to have a look on. Its nicely API-documented 
at java.sun.com and i think there was also a very good tutorial on Swing 
in particular.
Many of these patterns could easily be ported to c++, others might be a 
bit more tricky to port, since they depend on garbage collection, which 
is a luxury c++ can not effort/offer.

Hope this is usefull to you.
Lukas



Re: [linux-audio-dev] MVC again

2003-06-04 Thread François Déchelle
Lukas Degener wrote:



MVC sure is a great thing, but I would like to see a concrete
toolkit or a hint list which helps me in making perfect MVC
code immediately. Is it even possible to write a MVC toolkit?
(...)

What would be in such a toolkit?

Depends on what the toolkit is ment to do. The most consequent use of 
mvc patterns that i saw so far is found within the JFC/Swing classes. 
(Although there View and Controller are often(or always?) the same 
object iirc. )
It's been a long time since i last did something in java, so i can't 
come up with concrete class names, but i think that for instance there 
was this Table/TableModel etc. Actualy almost any gui component within 
swing is designed as a specific view on a certain data model, even 
for simple things: You could consider the JButton as View on a JAction 
model.

So if you want concrete examples of this and other  design patterns, 
this might be interesting to have a look on. Its nicely API-documented 
at java.sun.com and i think there was also a very good tutorial on Swing 
in particular.
Many of these patterns could easily be ported to c++, others might be a 
bit more tricky to port, since they depend on garbage collection, which 
is a luxury c++ can not effort/offer.

Hope this is usefull to you.
Lukas


Hi,

There is a good technical article explaining its architecture at:
http://java.sun.com/products/jfc/tsc/articles/architecture/index.html
Swing is based completely on the JavaBean event model:
http://java.sun.com/products/javabeans/
Basically, a JavaBean event is made of 3 classes:
 - an event class, which holds the state variables of the event
 - a listener interface (an abstract class if we speak C++) which 
defines methods that will be called upon notification of the event
 - a source object, which registers and unregisters listeners and fires 
calls to the listener's method when the event is trigged

The translation of MVC in term of JavaBeans is that a Model is an event 
source and the View and/or the Controler are listeners (more precisely, 
they use 'adapters' to translate the calls to the listener's method into 
calls of their own methods).

For instance, if you want to program in MVC a slider that follows an int 
value, you will need 3 classes:
 - an event class:
class IntEvent {
  ...
}
 - a listener interface:
interface IntListener {
  void valueChanged( IntEvent ev);
}
 - a source class (which is in fact in Swing an interface):
interface IntModel {
  void addIntListener( IntListener listener) {...}
  void removeIntListener( IntListener listener) {...}
  int getValue() {...}
}

and the graphical widget will be:
class Slider {
  Slider( IntModel model) {...}
}
And the gain is that your widget knows nothing about the way you store 
your data, if the value change is trigged by a message received other a 
socket or a inter-thread fifo etc...

Translating this model to C++ is possible, using abstract classes for 
interfaces and multiple inheritance for interface implementation.

However, something I'd be very happy to hear about is a translation in 
Python of the MVC architecture.

I think also that one of the computer science bibles can be worth 
reading: 'Desing Patterns' by E. Gamma, R. Helm  J. Vlissides.

BTW, not to promote my own kitchen, but jMax code uses a lot MVC :-)

François