Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design pattern for converting one model to another model

Basically, I have a number of objects in my application and I have to convert them to another third party objects before sending the request. On receiving the response I have to convert these objects back to objects supported by my application.

What pattern can I use for converting one model object to another in Java?

like image 768
Ashay Batwal Avatar asked Oct 25 '12 14:10

Ashay Batwal


1 Answers

I don't think there is a specific pattern for this, but you simply need a "converter" or "translator" class that takes in one object and returns another:

MyObject convert(ThirdPartyObject obj);
ThirdPartyObject convert(MyObject obj);
like image 56
casablanca Avatar answered Oct 12 '22 22:10

casablanca