tags:

views:

76

answers:

2

I have a WS ( CarASessionBean )it will call another WS ( CarBProxy ) to create a car details. So inside my CarASessionBean WS has a method call createCar : (In proxy has the same method as well call createCar just it take in CarB object as parameter).

public void createCar(CarA car) { 
     //here i will call the proxy and here error occur as CarBProxy take in CarB object
     ...
     **carBProxy.createCar(car);**
}

In this case is it possible to use wrapper? I just heard about wrapper not much understand what wrapper can do, can rougly guide me how to use wrapper i had reseached through google most example is about primitive type I was wonder is there possible to use wrapper to convert an object to another object. Example from CarA to CarB?

A: 

You could, but you'd be writing this wrapper yourself. There isn't anything built into standard Java that will do this for you. Something interesting in the Eclipse APIs is the IAdaptable interface which may be a pattern you want to use for this.

Jeremy Raymond
+2  A: 

This is referred to as the Adapter Pattern. Depending on the circumstances there's no reason you can't design CarB to wrap a CarA object. However, if you have two preexisting (non interface) classes CarB and CarA, converting one to another is going to be more than just a wrapper. Can you be a little more precise about what you're trying to accomplish?

Jherico
+1 for the Adapter Pattern.
edwardTheGreat
Adapter Pattern is an open framework?
Adapter Pattern is a design pattern (i.e. a concept, not an actual piece of software). This is made clear in the very first sentence of the Wikipedia page I linked to. I suggest you look at it.
Jherico
is basically to create an interface and implements it? correct me if i am wrong as I researched from google this is what i understnad