• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NX: Quick MVC Question

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If someone could briefly comment on the above Id be extremely grateful.
Many Thanks
Jamie
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic