File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Odd programming style

 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 490
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
I agree with the last comment but if you really want to use an object use Integer
 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic