Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design pattern to transform one type of data to another

I have to call a legacy SOAP webservice that sends a raw DataSet, from a clean(er) REST webservice that sends data described in JSON.

I need to transform this raw dataset that lists my objects into a true list of objects.

The dataset I get does not have enough informations, so the transformation is not "simple". It involves fetching additional data from the DB for each object.

What's the best design pattern to do this? My first naive reflex would be to create a method that takes this dataset as parameter, parses it, and returns a list of objects, but I feel there must be a better way of doing this.

I have seen the Adapter pattern, but I understand it "only" transforms an existing class into another that "looks like it". I want to completely change the data, from something akin to a table of strings with the id and name, into a true collection of instances with every useful info.

Update

I have another, similar problem coming up. We have both an old desktop application, and a new online application doing the same things, but in different ways. The save file for these two applications is very different, though.
I would like to create a convertor between these formats. The Mapper pattern, as suggested by @VS1 looks promising for this operation, but I don't think I would be able to use something as simple and straight-forward as AutoMapper. The Adapter pattern may also be of help. I'll look into these.

like image 668
thomasb Avatar asked May 21 '14 13:05

thomasb


Video Answer


1 Answers

You would need to either build a kind of Mapper on your own, that transforms your Dataset to objects; or you can use available tools such as AutoMapper.

These mappings require the knowledge of Adapter and Builder design patterns in general. I would emphasize more torwards Builder pattern to be more important in building this mapping.

You could also use LINQ and Extension Methods to achieve your requirement as per this example.

like image 60
VSS Avatar answered Oct 04 '22 13:10

VSS