views:

73

answers:

2

I have a Server application with a GUI. Written in c#. Now I want to use the MVC pattern for the whole Application.

Normally you have 1 Model, 1 Controller and maybe n views. Okay, I have one of everything, but I'm not sure with the Model.

My Situation: There are 1 server state, that can be online / offline, that has a client count, etc. This could be my "ServerModel". I will handle the network connection through my network library and create student object if one is connected. That all happens here. The view will be noticed if there is a new student and display a GUI element for the new student (through the controller). Now there is a action related to a special student in my view and the controller get notices "StudentChanged" and get the student that has changed.

The Question: The controller can now change the student directly OR tell the ServerModel how to change the student. The 2nd method seems to be overdone on the first look, but keeps the MVC design clear. I would like to change the student directly from the controller. But I'm not sure if this violation of the MVC (student is not a model but part of a model) brings any drawbacks in later development or the flexibility of the whole code.

Greeting from Hamburg ;)

A: 

Rule of thumb: keep the Model simple, let the Controller do its job.

tpdi
+1  A: 

The Controller should collect the information that the user wants to change about the student and hand it off to the View.

You may want to look at using the command pattern to bundle the actions needed to change the student.

For example

  1. The User does an action on the UI that he wants to change the student
  2. The UI notifies the View that the user wants to change the student via an interface.
  3. The View execute the ChangeStudent CommandObject
  4. The CommandObject displays a Change Student UI that has been registered with the View by the UI when the application started up.
  5. The User interacts with the Change Student UI. When the user is done the command retrieves the information.
  6. The command modifies the model and closes the ChangeStudent UI.
  7. The command notified the View it is done.
  8. THe view tells the UI the command is done.
  9. The UI updates.
RS Conley