In my application there is a model - Drug
class Drug{
String drugId;
String name;
String strength;
}
this interface takes a drugId and returns the Drug Model
interface IProcessor{
Drug getDrug(String drugId);
}
// easy flow
class ProcessorA extends IProcessor{
protected Drug getDrug(String drugId){
//get Drug from source A
return Drug
}
}
// From source B, I will be getting additional fields. Am not sure how i can append the new fields to the drug Model
class ProcessorB extends IProcessor{
protected Drug getDrug(String drugId){
//get Drug from source B
// Add few more fields specific to B
return Drug
}
}
1) Extend the Drug model (class DrugB extends Drug) for ProcessorB and add the new fields. In this case, I might be ending up typecasting the DrugB. Is this ok?
2) Add the common fields to Drug Class and use it. This is fine, but number of fields for each type of processor could be increasing.
Is there any patterns I should be thinking of. Please advice.
Aucun commentaire:
Enregistrer un commentaire