Mikael

Mikael

  • NA
  • 9
  • 0

MVC Pattern

Jul 20 2006 3:36 PM
Hi all!

I've recently begun rewriting an app i wrote not so long ago using c# and .net. The old app did what it was supposed to and the underlying code was fast, the problem was how i was using the .net form controls.

The handling of the controls wasn't something i'd recommend to anyone, small changes required the ui to rebuild entire listviews which slowed everything down quite a bit, it was a stupid solution.

The program isn't very advanced in what it's supposed to do, it's what it offers in choice of how to do something, when and with how much resources should be allocted for the task.

The program consists mainly of 3 main parts:
#1 - The UI (Net 2.0)
#2 - The TaskManager offering TaskQueueing in multiple threads etc
#3 - The data objects that get created, altered and the objects which store the data.

Since i don't want to mix the UI with the #2 and #3 parts of the program, i'm in a bit of a trouble. I was tipped about a pattern called the Model View Controller, or MVC for short.

It's pretty smart and has helped me greatly but it raises a lot of questions as well on how to solve my problems.

The patterns tells me to pass along ui events to the controller which updates the model part of the program (data). The UI should be listening to the model(data) part of the program for changes and update it's lists etc accordingly.

The problem i feel with that is that the UI has to handle the model events.

What i realy want is to have a controller that listens on both parts. Getting it's functions called when a certain UI event is invoked and it's event functions called when an event occurs in the data.

If i did it like this, i'd have to pass every single ui element to the controller in order for it to be able to update the controller.

Sure, the UI could listen to the model events and then tell the controller what happened and telll it to change a certain listview (by passing as a ref) to a certain function.

But, what i realy want is to hear your guys comment and how you would solve the problem of what calls what and who's responsible for what.