Mixing generics and polymorphism
Polymorphism, which attempts to hide differences in implementation, and generics, which attemtps to highlight them by providing exact information about types, don’t seem to mix very well. Consider the following fairly common pattern. class Base { } class Derived : Base { } abstract class Manipulator { List<Base> list; public Manipulator(List<Base> list) { this.list = list; } } class BaseManipulator : Manipulator { public BaseManipulator(List<Base> list) : base(list) { } } class DerivedManipulator : Manipulator { public DerivedManipulator(List<Derived> list) : base(list) { } } public static void Main() { List<Derived> list = new List<Derived>(); list.Add(new Derived()); DerivedManipulator d = new … Continue reading Mixing generics and polymorphism