This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
My colleague commented that I have an odd programming style. I was doing pass by reference to a method instead of returning the value directly. E.g.
He says I should just return the int and then the program would do whatever it wants. I prefer to return an object, then let the object have behaviour to react to the return value. What do you think? Bricks & bouquets welcomed.
I am not sure what you mean. Everything is pass by value, not reference.
If the calling method only needs an int from another object, why not pass just that? It is not like any manipulations of the value outside the object that returned the int can affect the int inside the object. If you need the whole object, then go ahead. Perhaps I am misunderstanding you, but IMO, it comes down to the specific situation, like most things.
"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Thanks for the clarification on the pass by value concept.
To clarify what I want to do. I pass in the object and the method will set the int type via accessor methods. That int member is mutable. Then once the method returns, I call a method to tell the object to perform the necessary handling.
Imagine now if I follow my colleague's recommendation
Just to make sure I undertand what you are trying to do.
1) Create an object 2) Pass the newly created object to doSomething so that its values are set
3) Do the logic
I hope I am on the right track so far.
1) Does doSomething need to know things about SomeObject to do its job? 2) Does doSomething return a value that ONLY SomeObject could care about? 3) Are the operations in the switch statement only valid for SomeObject?