As I mentioned in Reid's answers, you can use general methods to add both a tank and an airplane. Something like that:
class TwoTypesList<T1, T2> { List<Tuple<T1, T2>> m_list = new List<Tuple<T1,T2>>(); public void Add<ConcreteT>(ConcreteT item) where ConcreteT : T1, T2 { m_list.Add(Tuple.Create<T1, T2>(item, item)); } }
Then use will be:
TwoTypesList<IHaveColor, IHaveLocation> list = new TwoTypesList<IHaveColor, IHaveLocation>(); Airplane a = new Airplane(); Tank t = new Tank(); list.Add(a); list.Add(t);
The disadvantage, of course, is that you store the object twice. If you do not like this, then, of course, you can change the internal storage of the list as an object or only one of the interfaces.
source share