--00504502b079c59dd204684808d7 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 2009/4/24 Mike Stephens <rubfor / recitel.net>: > Robert Klemme wrote: >> >> The must have criterion for polymorphism is not classes but late >> binding. > > I think this is where we disagree. You seem to be saying polymorphism is > the ability for a piece of code to handle objects of differing types. No, that's not what I said. > I don't think that is necessary. It's perfectly alright for each > object-type to have it's own code to handle a method. Of course. But this code must be *executed*. > The only thing > that needs to be shared is the name, not its implementation. Correct. And depending on the language, the signature of two methods must be identical to be able to invoke them polymorphic. > This works just fine in early-binding contexts. Actually no. My C++ is a bit rusty these days but if you do _not_ declare a method as "virtual" and have a pointer of the base class type which points to a sub class instance the method invoked is actually the base class's method. This can only be remediated by late binding (declaring as "virtual") because only then the type of the object at hand decides about the method invoked. With the attached program you get: 09:32:19 Temp$ g++ t.cpp 09:32:36 Temp$ ./a.exe Base:a Base:b Base:a A:b Base:a B:b 09:32:43 Temp$ Here, only b() is invoked polymorphic. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ --00504502b079c59dd204684808d7 Content-Type: application/octet-stream; name="t.cpp" Content-Disposition: attachment; filename="t.cpp" Content-Transfer-Encoding: base64 X-Attachment-Id: f_ftwkhr8h0 CiNpbmNsdWRlIDxpb3N0cmVhbT4KCmNsYXNzIEJhc2UgewpwdWJsaWM6CiAgY29uc3QgY2hhciog YSgpIHsKICAgIHJldHVybiAiQmFzZTphIjsKICB9CiAgdmlydHVhbCBjb25zdCBjaGFyKiBiKCkg ewogICAgcmV0dXJuICJCYXNlOmIiOwogIH0KfTsKCmNsYXNzIEEgOiBwdWJsaWMgQmFzZSB7CnB1 YmxpYzoKICBjb25zdCBjaGFyKiBhKCkgewogICAgcmV0dXJuICJBOmEiOwogIH0KICBjb25zdCBj aGFyKiBiKCkgewogICAgcmV0dXJuICJBOmIiOwogIH0KfTsKCmNsYXNzIEIgOiBwdWJsaWMgQmFz ZSB7CnB1YmxpYzoKICBjb25zdCBjaGFyKiBhKCkgewogICAgcmV0dXJuICJCOmEiOwogIH0KICBj b25zdCBjaGFyKiBiKCkgewogICAgcmV0dXJuICJCOmIiOwogIH0KfTsKCnZvaWQgdGVzdChCYXNl KiBvYmopIHsKICA6OnN0ZDo6Y291dCA8PCBvYmotPmEoKSA8PCA6OnN0ZDo6ZW5kbCA8PCBvYmot PmIoKSA8PCA6OnN0ZDo6ZW5kbDsKfQoKaW50IG1haW4oKSB7Cgl0ZXN0KG5ldyBCYXNlKCkpOwoJ dGVzdChuZXcgQSgpKTsKCXRlc3QobmV3IEIoKSk7CglyZXR1cm4gMDsKfQo--00504502b079c59dd204684808d7--