• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Best approach to write helper private methods

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic