I currently have two derived classes, A
and B
, that both have a field in common and I'm trying to determine if it should go up into the base class.
It is never referenced from the base class, and say if at some point down the road another class is derived, C
, that doesn't have a _field1
, then wouldn't the principal of "least privileged" (or something) be violated if it was?
public abstract class Base
{
// Should _field1 be brought up to Base?
//protected int Field1 { get; set; }
}
public class A : Base
{
private int _field1;
}
public class B : Base
{
private int _field1;
}
public class C : Base
{
// Doesn't have/reference _field1
}
Base
,A
,B
,C
, and_field1
are. Those are important details that should not be left out; I think you should edit the question to talk about what those are.