Thanks, Dan...

I love the theory behind this kind of stuff!  Where can I get Cardelli's
paper?

Mark

-----Original Message-----
From: Dan Jacobs [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, January 16, 2003 7:04 PM

Hi Mark,

Contravariance is generally easiest to understand in the context of 
aggregation.  Consider the parameterized types (looking ahead to Java 
generics) List<Fruit> and List<Banana>, and variables fruitList and 
bananaList, and assuming that Banana is a subtype of Fruit.  Even though 
it should be ok in a polymorphic language to assign a value of [static] 
type Banana to a variable with a type of Fruit, it should be legal to 
assign a List<Banana> to the variable fruitList.  If you did, then 
static typing would indicate that you could add an Apple to that list, 
and that would be wrong!  It has to do with *static* (i.e. compile-time) 
typing, which is the kind of typing that makes most Java programs easy 
to understand.

There are some excellent papers by Luca Cardelli that deal with this in 
a much more rigorous manner, but they're not fun to read to your friends 
at parties :-).

In the context of this thread, contravariance is the mathmatical 
relation between types that exposes the dark side of inheritance.  This 
usually shows up when an "is-a-part-of" relationship is implemented as 
an "is-a-kind-of" relationship.  This results in a subclass that has 
operations that don't make sense for the superclass, or are just 
contradictory when applied to the superclass.  That's what I'm claiming 
is the problem with the current implement of form-beans.

-- Dan



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to