wood burning stoves 2.0*
The moose likes Java in General and the fly likes Code improvement: 2 similar methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Code improvement: 2 similar methods" Watch "Code improvement: 2 similar methods" New topic
Author

Code improvement: 2 similar methods

Matt Kurz
Ranch Hand

Joined: Jan 02, 2010
Posts: 40
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

Joined: Sep 08, 2007
Posts: 3064
    
  33

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.


Mohamed Sanaulla | My Blog
Matt Kurz
Ranch Hand

Joined: Jan 02, 2010
Posts: 40
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.
 
 
subject: Code improvement: 2 similar methods
 
Similar Threads
Hashtable sort by key
HashMap.get() != null vs HashMap.containsKey()
Defensive copies, Immutable clasess, HashMaps ArrayList
help with a sql statement
Currency Problem + General Advice