• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can I use Command in the Controller?

 
David Ding
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I plan to use Command pattern in the communication of View and Controller. The view sends CreateRecordCommand/UpdateRecordCommand/DeleteRecordCommand to Controller, in the Controller there's only one method handleCommand(Command cmd).
In SL-285 student guide, there're many methods in Controller such as handleXXXGesture().
Is my design a right MVC pattern?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,
There are many tiny variations you can make, and still be conforming to the MVC pattern. So your current way of implementing MVC is fine - your student guide is just recommending another variant.
The logic behind the student guide's variant (if I understand your description) is that the view should only be concerned with displaying the data, and all user interaction should be sent directly to the controller, which then works out what to do with it.
(This is the standard way of implementing MVC in web architecture: the view is usually a JSP and has no logic for handling user actions - the user actions are normally sent via a POST or a GET directly to a Servlet which acts as the controller.)
Your student guide should show how to get the user actions sent to the controller class. If not, you could take a look at the thread "Confused with MVC" in which Eugene Kononov provides an example of one way to do this.
Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic