This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Code improvement: 2 similar methods

 
Matt Kurz
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below 2 similar methods which connect per cxf to web service servers. Each method connects to a different one. How can I improve this code?

 
Mohamed Sanaulla
Saloon Keeper
Pie
Posts: 3159
33
Google App Engine Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are FirstService and SecondService, FirstItem and SecondItem and FirstServiceResponse and SecondServiceResponse not related to each other? You can create an Interface for Service and Item which these would implement and then in your connectWS1 method you can program to an interface. You should make your method unaware of the type by encapsulating the type information as well.
 
Matt Kurz
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamed Sanaulla wrote:Are FirstService and SecondService, FirstItem and SecondItem and FirstServiceResponse and SecondServiceResponse not related to each other? You can create an Interface for Service and Item which these would implement and then in your connectWS1 method you can program to an interface. You should make your method unaware of the type by encapsulating the type information as well.


I've thought about an interface, too, but it I'am unsure if it's without prblems to modify the automatic generated code of these classes. They were created by wsdl2java. I'am thinking about generics, too. Maybe a generic method would be fine to shorten the code until the for loop.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic