From: Dave Thomas Date: 2002-02-14T01:33:45+09:00 Subject: Re: qualms about respond_to? idiom "Jeff 'japhy' Pinyan" writes: > I believe the functionality was borrowed from Perl's universal object > method, "can". Perl code: I think Smalltalk _probably_ claims that honor. :) > As to *WHY* it's needed, it's there primarily because in Perl, classes can > inherit from multiple other classes, and dynamically, too. And if you > have to choose one of a set of classes, some of which are more capable > than others (this might be reaching...) it's nice to be able to say: > > my $object = AnyMailer->new(); > > if ($code = $object->can("PGP")) { > $object->$code($my_pgp_stuff); > } My point though was that for objects under your control you can normally avoid the need to test by using polymorphism. As your PGP example shows, bringing the test outside the object breaks encapsulation. Cheers Dave