Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method argument - Whole Object or individual attributes??

 
Varun Chopra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose I have this class:


I have a Utility class with following methods:


My question is, instead of String name/int id/Date dob - should we pass whole User object? I have seen some developers always passing the whole object instead of individual values. In such cases syntax is:


 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see the point in passing an entire User object if all you need is one of its values.

If you get your date of birth from another source, you would have to create a User object with bogus values for the other fields.


With both approaches you can mimic the other approach:

See why I'd prefer just having a Date object? Remember: you can get a Date from a User quite easily, but to get a User from a Date you need to create that new User.
 
Varun Chopra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic