MVC and Command Pattern questions

  • Thread starter Thread starter anonymous.user0
  • Start date Start date
A

anonymous.user0

Ok, this is kinda dumb. I'm trying to wrap my head around the use of
the MVC and Command Patterns. The questions basically concern where to
place code.
In the MVC pattern, where are the Commands instansiated? Are they
created by the Controller, or are they contained fully in the Model.
In other words, if I had a button that I wanted to use to save an
object is it something like this (not real code obviously):

button_click {
saveCommand = new SaveCommand(params)
App.CommandStack.Push(saveCommand)
}

or something like this:

button_click {
object.Save();
}

object.Save(){
saveCommand = new SaveCommand(params)
App.CommandStack.Push(saveCommand)
}

Should the API to the Application contain all user functionality of the
application, or should the Application just be a Command stack without
any knowledge of the Command themselves.

example:
Application{
Login(string username, string passphrase);
Logout(string username);
EndApplication();

viewObjectType1();
saveObjectType1(ObjectType1 item);
associateObjectType1WithObjectType2(ObjectType1 item1, ObjectType2
item2);
viewObjectType2();
saveObjectType2(ObjectType2 item);
...
}

vs.

Application{
DoCommand(Command command);
UndoLastCommand();
}

How should User Interface commands be implemented. Should there be a
type of ShowFormCommand that is passed to the application? or should
the Forms handle navigation themselves?

Any help would be appreciated.
 
One way to think of it that may help:

Model = data
Controller = API/Interface
View = GUI
 
Hmm, looking at the Controller as the API makes sense, but it seems
like it would get unwieldy, unless, of course, I have multiple
Controller classes. Otherwise my Controller class would be huge
,having all the functions available to the user within it (functions
that would basically be wrappers that dispatch the actual duties to the
Model).
While my application has a GUI, I'm thinking about how Command
Line/Batch Processing systems work. In typical (simple) Command Line
applications, you issue fully paramaterized commands, and wait for
results. Examples being 'ls -la', 'dir /w', 'echo', 'sed', etc. In my
head, each of these programs would be a Command object, the shell would
be the Application, my input the Controller, and the output the View.
Here the Commands are passed to the Application (where is the
Application in MVC?) which executes the Commands, without knowing
anything about them, and returns the result. The API would be all the
available Commands (everything in the bin directory). I'm gettting
really confused as to how things are supposed to break out and
seperate. Does anyone have any really good examples, or can point me
to some code/book that contains a good example.
 
Back
Top