Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Best approach to write helper private methods

 
Zbyszko Palka
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
What is the best way (practice) to write helper private method:

a) Method operate on instance variable 'someData'



b) ... or method operate on variable passed to it, and return result



BR
Zbyszko
[ August 12, 2007: Message edited by: Zbyszko Palka ]
 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would vote for the first method. I think it is better that passing member data be left out. In the future, if the member data format is changed, the second format must always be changed, whereas the first format may not have to be.

The first format is also easily changed to a public method in the future should it turn out that has some usefulness.

I think the second technique (data in, data out, with no member data modified) would be best when declared public static, in cases where external methods would also have some use for it in a general purpose way.
[ August 12, 2007: Message edited by: Red Smith ]
 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
duplicate
[ August 12, 2007: Message edited by: Red Smith ]
 
Zbyszko Palka
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

For me the first approach is more OO. It operate on objects variable. But from the other hand when I'am reading such code:



I can't find that doA and doB perform operations on someData. It is not clear ...

Hmmm, looks like there is no 'best approach', all depends on situation

Thanks!
Zbyszko
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic