Lecture overview -- Keyboard shortcut: 'u'  Previous page: Method Combination -- Keyboard shortcut: 'p'  Next page: Covariance and Contravariance -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 3 : 37
Object-oriented Programming in C#
Abstract classes, Interfaces, and Patterns
Parameter Variance

How do the parameters of Op in class A and B vary in relation the variation of A and B

Class B is a subclass of class A, and T is a subclass of S.

   A aref;
   B bref = new B();
   S sref = new S();

   aref = bref;    // aref is of static type A and dynamic type B
   aref.Op(sref);  // B.Op is called with an S-object as parameter.
                   // What if an operation from T is activated on the S-object?

An illustration of the problems with covariance.

/user/normark/oop-csharp-1/sources/c-sharp/co-contra-varians/ex.csThe full C# program.


It turns out that parameter variance is not really a relevant topic in C#...