Plain old covariance and contravariance

Jari-Matti Mäkelä jmjmak at utu.fi.invalid
Tue Oct 17 14:38:21 PDT 2006


BCS wrote:
> <rant type="soapbox">
> 
> One fix for this would be to allow explicit mappings.
> 
> class C:I
> {
>     void set(A a){}
> 
>     // quick and dirty syntax (not intended for final product)
>     alias
>     {
>         I.set(B) = set(A);
>     }
> }
> 
> 
> This would also allow a single class to implement several (3rd party)
> interface that have methods with the same signature but different
> semantics.
> 
> interface Critic
> {
>         //returns true if Critic approves of Subject
>     bool Opinion(Subject);
> 
>         //return a value indicating how much to trust critic
>     real Weight();
> }
> 
> interface PhyObject
> {
>         //returns height in feet
>     real Height();
> 
>         //return weight in lb
>     real Weight();
> }
> 
> class Person : PhyObject, Critic
> {
>     real Weight() // Now what?
> }
> 
> </rant>

It's better to use naming conventions to avoid these kind of semantic
collisions.



More information about the Digitalmars-d mailing list