un_guru
Joined: 14 Sep 2005 Posts: 32
|
Posted: Wed Oct 25, 2006 2:23 pm Post subject: MVC for DWT |
|
|
the title is not the name of the project, it's just the description.
What it is, and what it is not:
- it's not jface
- it doesn't hide dwt, it attaches to dwt controls offering more power
- it's a data awarenes (component/tool/library) for dwt
How it works:
I have two methods to implement this (in my mind) and I don't know which one to choose
1. The View and the Controler are merged in one class: Code: |
class ViewControl
{
this(parent , style, model)
{
...
}
/** Control part **/
onValidate() { ... }
onKeyDown() { ... }
handleDataChanged( event) { ... }
}
class Model
{
registerListener(event, delgate)
/* delegate is a member of ViewControl and it will be called on event */
notifyListeners(event)
// -- and functions to manage it's data
} |
The ViewControl knows exactly the model it uses all it's public members to interogate and instruct, while the Model is not aware of it's listeners, it just notifys 'em about data changes using a well defined mechanism.
Code: | ExtendedCombo c = new ExtendedCombo(parent, style, model);
ComboModel m = new ComboModel();
m.registerListener(DataChanged, &c.handleDataChange);
m.registerListener(NewData, &c.handleNewData);
// ...
// If the user imput doesn't exist in combo's list, the combo will notify the model via NotInListEvent;
...
handleNotInList() // member of ExtendedCombo
{
model.addData(this.getText()); // this might be this.combo instead
} |
The Model has means to verify data and accept it sending a NewData event to the ViewControl, or invalidate the request sending a NotValidData to the VC. The VC will decide if necesary to update it's display or notify the user or ...
2. The second method uses 3 classes The View is a basic DWT Widget, the Model is similar to the 1st methods Model, and the Controler is a gateway between the View and the Model, it also controls the behaviour of both
One would use standard DWT Widgets and standard defined models(or exdending standards), and create a control to manipulate both. The Controler receives notifications from both the View and the Model.
Code: |
ComboControler
{
this(Widget, Model) { ... }
onNewData() { // if needed update display}
onNotInList() { //if needed update model}
}
|
I think the second option would help produce cleaner code, and it's true separation of MVC components.
It's also easyer to port the second option to other D GUIs (like DFL). The model doesn't know about GUI and the Controler can be quite easily changed to use other Widgets. Anyway, this is not a GUI abstraction layer
Any ideas are welcome.
thank you
read more: http://en.wikipedia.org/wiki/Model-view-controller |
|