tags:

views:

24

answers:

1

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?

A: 

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