This is C# related, but actually the question is quite generic.
Let’s say that I have a base class
abstract class Base {
protected List<string> MyList = new List<string>();
protected abstract void FillMyList();
}
class Derived : Base {
protected void FillMyList() {
MyList.Add("test");
MyList.Add("test2");
}
}
This is ok, the derived class fills the MyList defined in the base class.
However, besides the abstract method name (FillMyList) – that hints that you actually HAVE to fill MyList – there is no clue to what this method is supposed to mean.
Is there a better way to enforce or (better) suggest strongly that you will have to fill MyList when you are inheriting from Base?
Maybe having the FillMyList declared as:
protected abstract void FillMyList(List<string> listToFill);
What do you suggest?
You can convert MyList to abstract property with getter, which derived must implementing