lundi 23 mars 2020

How to have different request and response for classes of same interface in Java?

Seems like that it is the usecase of generics and interface. I am not so fluent with java.

class A {
  String field1;
  Int field2;
}

//Let ITransformer is an interface. Every class which is implementing Itransformer have different output. Suppose 1 class returns the output and we update field1=output and for other class we need to update field2=output. transformers is the list of these classes.

A a = new A();
for(ITransformer transformer : transformers) {
    Object t = transformer.transform(vendorAspectReviewTransformerRequest); //don't know how to make sure that transformer of type 1/ or returning string should update field1 and other transformer should update field2 
}

Aucun commentaire:

Enregistrer un commentaire