In my Java service, I have two model classes with some common variables. The values of those variables are injected from properties.yml file. In the common method below, I want to pass any of the model class and use its methods as example given below. I cannot create multiple commonMethods because they would have same long code just different input model object. So how can I do that?
@NoArgsConstructor
@AllArgsConstructor
@Getter
public class ModelClass1 {
@Value("${xyz.abc.name:}")
private String name;
}
@NoArgsConstructor
@AllArgsConstructor
@Getter
public class ModelClass2 {
@Value("${xyz.pqr.name:}")
private String name;
}
public String commonMethod(/*imput either ModelClass1 or ModelClass2*/) {
return anyModelClass.getName();
}
I was thinking to create a common base model class with all public properties but that might not be a good practice.
0