Hey design pattern experts-
I’m trying to build a four step process into a VB.NET GUI. The application transfers objects from AppA to AppB.
The application will follow these steps:
- User constructs a general query in the GUI to identify which AppA objects to transfer.
- Model gets queryResults, datagrid in View lists each result
- User deselects items not to be transferred to AppB
- Model transfers selected items
I’m new to MVC and am trying to figure out how this should work. I’ve have the following functions implemented in the model, but don’t know the MVC-way to tie them into my GUI:
Function getQueryResults(queryParams) as Items
Function transferItems(items)
Do I keep the Items data structure in the model?
How do I remove deselected from the Items data structure without building logic into the view?
Both of the above functions take time, how can I design thing to allow me to BackgroundWorker the model’s functions?
Thanks
Please note that I’m a C# rather than VB dev, but it should work the same way regardless.
Think of your view as being really, really dumb.
Your view shouldn’t have any logic in at all. Every time it sees the user do something (like deselecting an item) it should tell the controller. Every time the controller wants the Gui to display something new, it should tell the view to do that. Normally there’s a subject / observer pattern between the view and the controller or between the model and the view, so that the view will automatically update or notify the controller when things happen.
In this instance, imagine a conversation like this.
You can either keep the Items data structure in your domain object, or you could just make the list of Items your Model for MVC purposes.
A nice thing to do which makes it more like MVP or MVVM would be to present the view with a wrapper around the model giving it exactly what it needs and only what it needs – so for instance, you could give it a wrapper which included the items and also a flag which said “busy” for when your worker is off doing stuff.
Hope this helps.