开发者

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");
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜