mercredi 7 novembre 2018

Design pattern to convert multiple object to a common object

I'm integrating with a third party service which takes a specific object as input. There are multiple scenarios where I've to use this service with different parameters. Then I've to transform each of them to the common object.

Input to the Third Party Service:

Class ProcessorInput{
 String attribute1;
 String attribute2;
 String attribute3;
 Integer attribute4;
 .
 .
 .
}

Caller 1 input Object:

class Caller1{
  String A1 // maps to attribute1 of the processorInput
  String A2 // maps to attribute2 of the processorInput
  Integer A3 // maps to attribute4 of the processorInput
 .
 .
 .
}

Caller 2 input Object:

    class Caller2{
      String A1 // maps to attribute1 of the processorInput
      String A2 // maps to attribute2 of the processorInput
      String A3 // maps to attribute3 of the processorInput
     .
     .
     .
}

What would be the good design pattern to convert the two objects in common object i.e. Caller1 -> ProcessorInput & Caller2 -> ProcessorInput

Aucun commentaire:

Enregistrer un commentaire