• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S: private method signature

 
Steve Taiwan
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • 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
 
James Turner
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • 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.
 
mike acre
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
Thank James!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic