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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With