• Post Reply Bookmark Topic Watch Topic
  • New Topic

Suggestion required of using single method for two different operations.  RSS feed

 
sohaib yasir
Ranch Hand
Posts: 51
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a single method for saving and updating records. In case of saving i need to return auto generated tokenNumber and on updating i need to tell only that record has been updated on base of record updated or not. I am unable to get how to achieve it in a single method. i would really appreciate if correct my technique if am doing wrong.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The idea of doing two different things in the same method is doubtful at best. I can see no point to any of those three methods. Why don't you simply use save(p) and update(p) where p is a Patient object?
 
sohaib yasir
Ranch Hand
Posts: 51
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:The idea of doing two different things in the same method is doubtful at best. I can see no point to any of those three methods. Why don't you simply use save(p) and update(p) where p is a Patient object?


Because there is a single button on screen which is used to save and update records.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How daft, making the application fit the display. The display should match the application.
Try one method, with if (this.contains(p)) … else …
Of course, you now have two incompatible return types. You have the option of returning the ID string regardless, or returning nothing. If the Patient class has a field for ID, you can give it a setID methodIt looks as if you had been given some iffy design to try to correct.
 
sohaib yasir
Ranch Hand
Posts: 51
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell Ritchie. I clicked the idea.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome

Another possibility is to change the Listener on the button depending whether you are entering a new patient or an old patient.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!