From: dblack@... Date: 2002-09-16T23:37:32+09:00 Subject: Re: not grasping the method overloading/multi-dispatch thing Hi -- On Mon, 16 Sep 2002, Philipp Meier wrote: > Coming from a java background if do not feal comfortable with Mixins, > yet. Altough I must admist this a clever use of them. Nevertheless I fear > a clash of method names if more than a few mixins are used on business > methods. Imaginge you want to extend to example by a to_xml method. > Accidently you name the tag method "tag" like the one for HTML. (Assume > the XML aspect is defined in another place than the HTML.) This could > lend to real confusion, IMHO. I know, I know there are Unit Tests that > should catch this but I stell consider it a slight smell. One would be > on the safe side, if one could tell to call the method defined in a > certain module: > > module Foo > def qux > 5 > end > end > > module Bar > def qux > 7 > end > end > > class Baz > include Foo > include Bar > end > > Baz.new.qux # => 7 > > # How can I call Foo.qux on Baz?? My best shot, subject to wizardly overrule: You're right that you can't do that, because the Baz object sees only a straight line to its #qux method, not a choice. In general terms, I've found that the best way to think of it is that including a module is very similar to typing in the module's code in the file that's doing the including. Not identical (because of scoping things, etc.), but similar. A consequence of this is that including two modules with clashing method names can be regarded as a programming error of the same kind and degree as accidentally writing two methods with the same name in a single class/file. In other words, you're responsible for knowing as much about the modules you include as about the methods you wrote 100 lines back, because they're all equally part of the object interface you're designing. David -- David Alan Black | Register for RubyConf 2002! home: dblack@candle.superlink.net | November 1-3 work: blackdav@shu.edu | Seattle, WA, USA Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com