• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: Quick MVC Question

 
Jamie Orme
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
I have looked at a number of MVC posts on this forum, and have coded accordingly. However, I still want to verify that I have implemented my controller correctly. As I understand things the controller accepts actions from the user via the view and passes them onto the model, which in turn will update the view. In my code (Contractors assignment) I have something like the following in my controller:

Notice that the bookContractor() method does more than simply pass the action onto the model, unlike my getContractors() method:

I would like to know if the additional checks, etc., in my bookContractors() method are OK.
Both methods are called via the callback mechanism proposed by Mark and Eugene.
All help will be much appreciated.
Many Thanks
Jamie
[ June 09, 2003: Message edited by: Jamie Orme ]
[ June 09, 2003: Message edited by: Jamie Orme ]
[ June 09, 2003: Message edited by: Jamie Orme ]
 
Jamie Orme
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If someone could briefly comment on the above Id be extremely grateful.
Many Thanks
Jamie
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jamie,
My opinion is that the view should do what validation it can with the data it has - the controller should only be used for passing on events to the class that can handle them.
The controller can do work on the data it is given by the view, especially if one action performed in the view requires more than one event to be generated for one or more models.
However it appears in your case that the view should already know if the particular contractor to be updated has already been booked, in which case I would expect pre validation in the view to reject the action.
Hopefully Eugene will confirm this or correct me. Unfortunately Mark is away at present.
Regards, Andrew
 
Jamie Orme
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply Andrew. I tend to agree with the point you have raised. As this has been bothering me for some time I have now changed my controller so that the book method is similar to the following:

The processBooking() method on the view will now throw a ContractorException if the pre-validation fails. E.g.

Im a bit happier with this. What do you think? Anyone else care to comment?
Cheers
Jamie
[ June 10, 2003: Message edited by: Jamie Orme ]
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jamie,
Personally I would prefer pre validation to be done before bookContractor gets called.
From the perspective of a person trying to debug your code: class A calls class B which calls class C with the result of a call in class A.
If you can do the validation prior to this, then it should be easier to debug.
Just my 2 cents worth.
Regards, Andrew
 
Jamie Orme
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew
I see what you mean! Having had a good look at my code I now fully understand the points you have raised (especially after revisiting one of Eugenes examples). So I have modifed my code again, so that all validation is now done in and by the view BEFORE (and not inside) the bookContractor method on the controller.
Many thanks for all your help,
Jamie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic