Is it a pretty safe assumption that the following class is an odd representation of “downgrading” (for lack of a better word) the private class field?
public class AggregatedClass : ICollection<SingleClass>
{
List<SingleClass> _singleClassList;
// ...rest of code
}
I recently saw a “working” example of this, and it threw me for a bit of a loop. What is the point of the above? If List<T> implements ICollection<T>, then isn’t the above class a reversal? You’re having a private class field that’s type class is an extension of it’s parent’s class implementation (ICollection<T>).
Is it accurate to say the above example is not really a great design?
This abstracts the
List<T>as an implementation detail, and ifappropriate / needed the class can now provide additional logic in the various methods of the list (Add/Remove etc; noting that these are non-virtual on List-of-T).If you mean the field should be ICollection – well, that is up to the class! It might be making use of the additional List-of-T methods, or it could just be an irrelevant implementation detail, that was handy for whoever wrote the class, and does no harm since it is private anyway.