From: Philipp Meier Date: 2002-09-16T23:11:14+09:00 Subject: Re: not grasping the method overloading/multi-dispatch thing --DqhR8hV3EnoxUkKN Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Sep 14, 2002 at 08:03:10AM +0900, Patrick May wrote: > Philipp Meier wrote in message news:<200209131019= 10.GC17997@o-matic.net>... > > On Fri, Sep 13, 2002 at 02:22:25PM +0900, Patrick May wrote: > > Because of Rubys dynamic nature this is IMHO always possible. But is it > > good design? You will agree, that, as an example, code that formats a > > business object for reporting certainly does not belong into the busine= ss > > object class but in a reporting class. >=20 > Code should execute in the namespace close to its data. That said, > Ruby lets you use modules to clearly separate the code within a given > namespace. See below. > or, using modules: > Which is the preferable design? Note the differences from the > perspective of a user of the api (PolyTest.test): >=20 > No mediating functions. No arguments to forget when calling > :to_html/:to_rtf. No binding between the output stream and > :to_html/:to_rtf, though I realize your example could be changed to > avoid that binding. >=20 > The implementation is also short (~10 fewer LOC) and simple -- not a > single conditional to implement this behavior! >=20 > Once you've decided to create an object, you shouldn't need anymore > conditionals on that type. It's nice to have such conditionals, and I > use them in my code, but they are refactoring targets to me. 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 # =3D> 7 # How can I call Foo.qux on Baz?? -billy. --=20 Meisterbohne S=F6flinger Stra=DFe 100 Tel: +49-731-399 499-0 eL=F6sungen 89077 Ulm Fax: +49-731-399 499-9 --DqhR8hV3EnoxUkKN Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9heaqfBriNoqItSYRAu7oAJ9kryhHP33O6F031iPHTn8D0Poy8gCgjTWj li4ToZe4giZ6aQvIm/s5yIk= =BPSm -----END PGP SIGNATURE----- --DqhR8hV3EnoxUkKN--