473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

MVC and Command Pattern questions

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.

Jan 25 '06 #1
2 3425
One way to think of it that may help:

Model = data
Controller = API/Interface
View = GUI

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Charles Cox
VC/VB/C# Developer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

<an*************@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
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.

Jan 25 '06 #2
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.

Jan 26 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: TEK | last post by:
Hello I'm wondering if anyone out there might give some input/suggestions/viewpoints around the Command pattern. In my case, the number one priority for using the pattern is undo support. Some...
1
by: Peter Rilling | last post by:
I have an EXE that I would like to be able to run from either the command-line or as a windows service. Is there a way that I can tell which context the program is running in? Basically, if it...
3
by: Samuel R. Neff | last post by:
We're working on implementing a Command Pattern design with our application in order to help facilitate undo/redo. This is fine four user actions we control which basically means menu actions. ...
8
by: Charles Law | last post by:
I am implementing the command pattern in VB.NET, where the commands have been serialised. That is, I have several classes that all inherit from my base Command class, that implements ICommand...
6
by: kd | last post by:
Hi All, I found the 'Inlist' function of foxpro very useful. Is there any command in vb.net that does the same job? Thanks. kd
4
by: FluffyCat | last post by:
New on November 29, 2005 for www.FluffyCat.com PHP 5 Design Pattern Examples - the Command Pattern. Since you all enjoyed the Visitor Pattern so much yesterday, today I have the Command Pattern...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
7
by: Bin Chen | last post by:
Hi, I want to do following: get a user input regex, then pass this as a parameter to grep, and then get the result from grep. Any code snip to implement the similar function? I am a python...
1
by: Reg | last post by:
Hello, I have a situation where a text based protocol comes to my component to be handled. Protocol has differnt commands and they have different arguments. The question is that which is in C#...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.