aspose file tools
The moose likes Beginning Java and the fly likes method argument - Whole Object or individual attributes?? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "method argument - Whole Object or individual attributes?? " Watch "method argument - Whole Object or individual attributes?? " New topic
Author

method argument - Whole Object or individual attributes??

Varun Chopra
Ranch Hand

Joined: Jul 10, 2008
Posts: 204

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:




-Varun -
(My Blog) - Mock Tests
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

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.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Varun Chopra
Ranch Hand

Joined: Jul 10, 2008
Posts: 204

Thanks Rob
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: method argument - Whole Object or individual attributes??
 
Similar Threads
date mapping problem in Hibernet
Nesting ognl expressions?
Data Retention in JSPs
Bridge between REST & WS
modifying a list collections