某些类中有一些方法和成员变量看起来非常相似,我想我可以重构和抽象它们......但我不确定这是否是正确的方法:
例如,假设我有这两个类:
public class CaseField
{
private int mlObjectKey = CommonIndepClass.GetNextObjectKey();
public int ObjectKey
{
get
{
return mlObjectKey;
}
}
// some other specific methods...
}
然后是另一个类:
public class AsOfField
{
private int mlObjectKey = CommonIndepClass.GetNextObjectKey();
public int ObjectKey
{
get
{
return mlObjectKey;
}
}
// some specific methods ...
}
所以我在想是否正确创建一个抽象类并将这些方法和成员变量分解并将它们放入该抽象类中:
public abstract class CommonFields
{
private int mlObjectKey = CommonIndepClass.GetNextObjectKey();
public int ObjectKey
{
get
{
return mlObjectKey;
}
}
}
public class CaseField: CommonFields
{
// just its own specific methods and member variables.
}
public class AsOfField: CommonFields
{
// just its own specific methods and member variables.
}