• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

one webmethod calling another inside same web service  RSS feed

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have a webservice with one @WebMethod (say Method#1) . I have a need to add another @WebMethod (say Method #2) where I need most of the code that I had placed inside Method #1.

I have 2 ways to do this
a) Call Method#1 inside Method#2 and then proceed with additional code for Method#2
b) Move the common code into a private method and have both Method#1 and Method#2 use the common logic.

I am not comfortable using (a) because of calling one public @WebMethod from another public @WebMethod just to reuse code

Please advice if I can use (b) over (a) or any other better way of doing this

Ranch Hand
Posts: 2198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally, I would choose option b because:
- From just looking at the program, it is obvious that method1 and method2 has code in common.
- I feel that there is a greater risk that someone else modifies method1 without realizing it is used by method2 adn thus causing errors that may be more or less subtle if method2 calls method1.
I feel that refactoring common functionality to a private method gives a more clear signal that the code is used at multiple places.
- I would also want to avoid calling a method that is exposed in the web service from within another method that is also exposed in the web service.
I don't have a rational explanation for this, just a feeling...
Best wishes!
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!