I have a helper class which has a method that perform some checks against a field in a model. I have two models, ModelA and ModelB, they have some similarities but not all. One of them is they both have a field, lets say string ProductCheckField. The ProductCheckMethod returns back the Model, because of that it has created duplication of methods which does the same thing but returns a different model. Even the extracted methods are duplicates. Is there a good design pattern or any other good practice/technique I can use to eliminate duplication of having to create two methods?
N.B I can't use a shared Interface as the models are not the same.
Currently I have..
public class ModelA
string blah..
int blah
.....
string ProductCheckField
public class ModelB
string xyz
int xyz
.....
string ProductCheckField
public class HelperClass
{
public ModelA ProductCheckMethod(ModelA model)
{
/// do somthing
performX(model);
checkY(model);
return model;
}
public ModelB ProductCheckMethod(ModelB model)
{
/// do somthing
performXDuplicate(model);
checkYDuplicate(model);
return model;
}
}
ModelAandModelBhave duplicate checks, why are the duplicate bits not shared in some third class?check(modelA.X); check(modelA.Y),check(modelB.X); check(modelB.Y)and the such. Without more concrete examples, it's hard to say.