wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Odd programming style Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Odd programming style" Watch "Odd programming style" New topic
Author

Odd programming style

Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

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.

Regards,

Pho
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
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
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I agree with the last comment but if you really want to use an object use Integer
Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

Rusty,

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.

e.g.



Imagine now if I follow my colleague's recommendation



I encapsulated the switch inside SomeObject.

Comments?
Jim Toy
Greenhorn

Joined: Oct 17, 2002
Posts: 14
Pho,

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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Odd programming style
 
Similar Threads
ArrayList, contains, objects
Sorted TreeSet from HashSet
Application Related
Concurrent calls to static methods
null == someobject