Suppose there is a third party library containing base class Transformer and concrete implementations TransformerA and TransformerB.
I need to write parallel classes for TransformerA and TransformerB outputting class say TransformerNew
public class TransformerAConverter {
public TransformerNew convert(TransformerA transformerA) {
// conversion logic
}
}
public class TransformerBConverter {
public TransformerNew convert(TransformerB transformerB) {
// conversion logic
}
}
I need to write following function:
public TransformerNew[] process(Transformer[] transformers) {
}
How can I achieve this without instanceof or explicit type casting. I have tried using visitor pattern but unable to express it.
Aucun commentaire:
Enregistrer un commentaire