• 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

B&S: private method signature

 
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am reconsidering my private method design.
I have the following 2 methods and they do the same thing.
However, I see most of candidates here use METHOD 2.
Can someone tell me why METHOD 2 is better??

METHOD 1: public void validateRecNo(long recNo) throws RecordNotFoundException
pro: Throw RecordNotFoundException with the exact, actual reaon
con: client doesn't have his control when calling the method.

METHOD 2: public boolean isValidRecNo(long recNo)
pro: client can do what he wants according to boolean value
con: client doesn't know what happens
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Steve,

I use method 1. I find this better because once you call the method you can simply continue with your code without needing to test anything. If the record is not valid the catch clause will handle it.

I find this makes the code cleaner and easier to understand. If the method does not throw an exception assume the record is valid.

James.
 
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Method 2 Pro: You can call it when throwing an exception would not be exceptional behaviour.

In my case this made it the reason to go for method 2
 
Steve Taiwan
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Mike.

Can you explain your reason more?
I really don't understand what you tried to explain.
Thank you.

Dear James.

Thank you for the reply.
[ October 05, 2004: Message edited by: Steve Taiwan ]
 
James Turner
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know that Hibernate use method 1 as the way they do record validation.

I am sure they though about the best way out of the two methods.

James.
 
Steve Taiwan
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank James!!
reply
    Bookmark Topic Watch Topic
  • New Topic