• 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

Placement of a read method

 
Ranch Hand
Posts: 147
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I had a discussion with a colleague about the placement of a method. The setup is this: I have project based on the MVC pattern. I have a controller, I have a User-class and I have a class that manages my input and output. Now my user tries to login. I thought my controller should ask the database for a User object and use this. My colleague said that it would be better to create a new User object in the controller, and leave reading to it (so that the user knows about the input and output class). Same goes for saving the User (in case of changes).
Both versions work, of course - but what would be better?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jan Hoppmann wrote:I had a discussion with a colleague about the placement of a method. The setup is this: I have project based on the MVC pattern. I have a controller, I have a User-class and I have a class that manages my input and output. Now my user tries to login. I thought my controller should ask the database for a User object and use this. My colleague said that it would be better to create a new User object in the controller, and leave reading to it (so that the user knows about the input and output class). Same goes for saving the User (in case of changes).
Both versions work, of course - but what would be better?


Interesting question.

On balance, I would say I agree with your colleague: that the login process should be part of the controller, and that it should hand you back a fully-functioning User object - and certainly one that knows how to save itself.

However, that doesn't preclude you from having an object that handles I/O; it just means that functions that have anything to do with a User are dealt with by that User - I presume there's nothing to stop your User object from calling your I/O manager if it needs to.

Winston
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic