Stewart Stremler wrote:
Since every object of type Bar is *also* of type Foo, we can "widen" the type. Code that has a variable of type P can treat objects of type Q as if they were of type P, because every argument they can provide to P would work with Q.
Note that this is called contravariance. It's the "right" thing to do theoretically, and unpleasant in many pragmatic cases, because it's going the "wrong" direction in some sense.
The return type is covariant - you subclass the type, and return a subclass of the inherited return type.
The arguments are contravariant - you subclass the type, and accept superclasses of the inherited arguments.
But when you specialize a class, you often want to accept specialized arguments. When you specialize what Java calls "Vector" to only accept actual vectors (i.e., tuples that are invariant under coordinate transforms) then you want "add" and such to only take arguments of the same subclass.
http://www.faqs.org/faqs/eiffel-faq/ (See the LCON question) -- Darren New / San Diego, CA, USA (PST) His kernel fu is strong. He studied at the Shao Linux Temple. -- [email protected] http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg
