F
Francesc
Hi,
After some years programming libraries and web based applications I'm
trying to program my first not-silly windows application (something
similar to an editor but just to annotate text lines).
After some trials just putting some code directly at the control events
I tried to refactorize a little. But after read some documents on CMV
(Controller-Model-Viewer) pattern I spent all this week trying
unluckily to use it.
First subject:
==============
I'm not sure to understand completelly how this pattern is implemented
in real *code*. For example:
- Is the Controller the winForm? I thought yes, because it is which
receives the user event, it isn't?
- Is the Viewer also the winForm? I thought yes, because it is who
display the model representation.
But, How the model informs to the Viewer that it must refresh the view
(in this case the RichTextBox).
Second subject:
===============
A less general problem. I have coded the next "big" classes:
* zApplication: It's a blackbox that models all the logic and behavour
of the application. All control events are pass through to methods of
this object.
(Menu->OpenFile) event = { zApplication.OpenFile(<????>);}
Inside this zApplication I have two objects:
* zDocument: It's the model of the content that it's edited. It has
some properties (CurrentLine, ...) and methods (MoveDownCurrentLine or
DeleteCurrentLine).
(KeyDown) event = { zDocument.MoveDownCurrentLine; }
(KeyEnter) event = { zDocument.DeleteCurrentLine; }
* zViewer: It's a dumm class that returns the "graphical" (in fact it
is a RTF representation) version of zDocument: the text with numbered
lines and the background of the CurrentLine colored yellow.
richTextBox.RTF = zViewer.RenderedDocuement;
Problem:
========
To "copy" the updated RTF rendering I use the previous code, but I'm
not happy that the "controller" (the winForm) is who handles the
updating.
Another problem is that zDocument must return bools for every command
in order to inform the "controller" that the command implies a refresh,
and "controller" must check thems all the time, using code like:
if (zDocument.MoveDownCurrentLine== true)
{
zViewer.UpdateRendering(zDocument);
RefreshRTF();
}
private RefreshRTF();
{
richTextBox.RTF = zViewer.RenderedDocument;
}
Someone has been so nice to read as deep in this awfull english
message?
Some of the nice guys who did know some way to refactor this design in
order to be cleaner and/or most similar to the CMV spirit?
Thanks very much, I'm really lost... :-/
[Note: The "pseudo"-code was write as an indication, sure that it has a
lot of syntax errors not useful in this thread.]
After some years programming libraries and web based applications I'm
trying to program my first not-silly windows application (something
similar to an editor but just to annotate text lines).
After some trials just putting some code directly at the control events
I tried to refactorize a little. But after read some documents on CMV
(Controller-Model-Viewer) pattern I spent all this week trying
unluckily to use it.
First subject:
==============
I'm not sure to understand completelly how this pattern is implemented
in real *code*. For example:
- Is the Controller the winForm? I thought yes, because it is which
receives the user event, it isn't?
- Is the Viewer also the winForm? I thought yes, because it is who
display the model representation.
But, How the model informs to the Viewer that it must refresh the view
(in this case the RichTextBox).
Second subject:
===============
A less general problem. I have coded the next "big" classes:
* zApplication: It's a blackbox that models all the logic and behavour
of the application. All control events are pass through to methods of
this object.
(Menu->OpenFile) event = { zApplication.OpenFile(<????>);}
Inside this zApplication I have two objects:
* zDocument: It's the model of the content that it's edited. It has
some properties (CurrentLine, ...) and methods (MoveDownCurrentLine or
DeleteCurrentLine).
(KeyDown) event = { zDocument.MoveDownCurrentLine; }
(KeyEnter) event = { zDocument.DeleteCurrentLine; }
* zViewer: It's a dumm class that returns the "graphical" (in fact it
is a RTF representation) version of zDocument: the text with numbered
lines and the background of the CurrentLine colored yellow.
richTextBox.RTF = zViewer.RenderedDocuement;
Problem:
========
To "copy" the updated RTF rendering I use the previous code, but I'm
not happy that the "controller" (the winForm) is who handles the
updating.
Another problem is that zDocument must return bools for every command
in order to inform the "controller" that the command implies a refresh,
and "controller" must check thems all the time, using code like:
if (zDocument.MoveDownCurrentLine== true)
{
zViewer.UpdateRendering(zDocument);
RefreshRTF();
}
private RefreshRTF();
{
richTextBox.RTF = zViewer.RenderedDocument;
}
Someone has been so nice to read as deep in this awfull english
message?
Some of the nice guys who did know some way to refactor this design in
order to be cleaner and/or most similar to the CMV spirit?
Thanks very much, I'm really lost... :-/
[Note: The "pseudo"-code was write as an indication, sure that it has a
lot of syntax errors not useful in this thread.]