Conversation started May 16, 2015 at 21:20.
May 16, 2015 21:20
people rarely recognize things as type system problems because they aren't used to thinking in those terms; the crux of it is he has an object Person with an Addresses property, but he wants to inherit from Person with American and make Addresses no longer be an Address[] but be an AmericanAddress[]
problem is Addresses is defined in Person so American can't change it's type (AmericanAddress maybe adds the State property)
Solution: Generics. class Person<T> where T : Address { T[] Addresses { get; set; } } and then class American : Person<AmericanAddress> { ... }
Where did he mention addresses?
@RobertHarvey I made up the example
I was just reiterating his problem in my words - as I understand it.
it's a type system problem because it's about wanting to have a derived type replace the types of properties from the base type
sounds plausible enough to me (I couldn't parse the full wall of text either)
So the Addresses property on Japanese is of type JapaneseAddress and on American it's of type AmericanAddress
and there is no longer a JapanesePerson or AmericanPerson at all, just a Person<T> and some "normal" inheritance from Address to WhateverAddress, right?
May 16, 2015 21:24
It's generally bad design, but that's the problem and solution.
@Ixrec no, there's JapanesePerson which implements Person<JapaneseAddress> and AmericanPerson implements Person<AmericanAddress> so that the base class has a property T[] Addresses which can have it's type selected by those derived classes
hm, okay, close enough I guess
public class Person<T> where T : Address
{
    public T[] Addresses { get; set; }
}
 
Conversation ended May 16, 2015 at 21:26.