| 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
|
 |
 |
|
|
subject: method argument - Whole Object or individual attributes??
|
|
|