I'm quite new to abstract classes. Usually you can create a member in a base-class and then extend its logic by calling it in the subclasses using base.Member. But can I do it the other way around?
I have an abstract class A with a property of type IEnumerable<T>:
abstract class A
{
IEnumerable<int> Foo { get; }
}
I want the derived classes of A to return an individual IEnumerable and want to "filter" them using .Where by the same condition. I did following:
abstract class A
{
public IEnumerable<int> Foo => Bar.Where(x => true);
protected abstract IEnumerable<int> Bar { get; }
}
abstract class B : A
{
protected override IEnumerable<int> Bar {
get { yield return 1; }
}
}
It works, but is this the right approach? Or can I do the same thing using only one property? It feels especially clunky if I have some classes between which also have to filter it because I'd just have to add more and more members based on the amount of layers I have.