May 07, 2006 Re: polymorphism: overloading vs. overriding | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bruno Medeiros | Bruno Medeiros wrote:
> Mike Parker wrote:
>>
>> This line is the key:
>>
>> Foo foo = new Bar();
>>
>> foo is an instance of Foo, not an instance of Bar,
>
> No, that is wrong, foo *is* an instance of Bar. (yet, it's type contract is only that it is a Foo)
>
Yes, yes. Underneath the foo is an instance of Bar. But because, as you say, the type contract is that of Foo then you are effectively dealing with a Foo and not a Bar. It should only be treated as a Bar when you downcast.
|
May 07, 2006 Re: polymorphism: overloading vs. overriding | ||||
---|---|---|---|---|
| ||||
Posted in reply to Markus Kranz | Uh, I didn't know the issue of "covariance versus contravariance" is a topic of continuing debate: http://c2.com/cgi/wiki?ContraVsCoVariance and especially http://www.cs.trinity.edu/~mlewis/CSCI3294-F01/Papers/p431-castagna.pdf where I found on page 10: "At this point, we are able to make precise the roles played by covariance and contravariance in subtyping: contravariance is the correct rule when you want to substitute a function of a given type for another one of a different type; covariance is the correct condition when you want to specialize (in object-oriented jargon "override") a branch of an overloaded function by one with a smaller input type." Regards, Markus |
June 15, 2006 Re: polymorphism: overloading vs. overriding | ||||
---|---|---|---|---|
| ||||
Posted in reply to Markus Kranz | Markus Kranz wrote: > Uh, I didn't know the issue of "covariance versus contravariance" is a topic of > continuing debate: > > http://c2.com/cgi/wiki?ContraVsCoVariance > > and especially > > http://www.cs.trinity.edu/~mlewis/CSCI3294-F01/Papers/p431-castagna.pdf > > where I found on page 10: > > "At this point, we are able to make precise the roles played > by covariance and contravariance in subtyping: contravariance is the correct rule when you want to substitute a function of a given type for another one of a different type; covariance is the correct condition when you want to specialize (in object-oriented jargon "override") a branch of an overloaded function by one with a smaller input type." > > Regards, > Markus > > I finally took the time to read it, it is indeed a good article. -- Bruno Medeiros - CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D |
Copyright © 1999-2021 by the D Language Foundation