How to expose multi-element field in base class to derived classes
I have a base class that declares a grouping of objects. That grouping can be an array, List, Collection, that's up to me.
The derived classes of this base class are the ones that actually set the values of this multi-element field开发者_开发百科. What is the best way to expose this field to the derived classes?
Expose it via a protected minimal interface:
class Base {
private List<string> _elems = new List<string>();
protected ICollection<string> ElementStore { get { return _elems; } }
}
class Derived : Base {
public Derived() {
ElementStore.Add("Foo");
ElementStore.Add("Bar");
}
}
精彩评论