When to move a common field into a base class?
11
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 }
object-oriented inheritance abstract-class
...