-----BEGIN PGP SIGNED MESSAGE-----
Shin guey Wong wrote:
| Julian L. wrote:
|> A module is simply a place where you can store methods.
|> Thus, you can include a module as a mixin in a class, and it will get
|> all the methods.
| Yes, but we can achieve the same thing by inherit a class which will get
| all the methods also.I know we can mixin multiple classes but only
| inherit 1 class.
| If there is only 1 class/module, which we should use? create a module or
It depends, actually. A module provides a namespace, and (ideally)
prevents namespace collisions.
It also provides grouping of classes (well, d’uh. I’m amazed at my
insightfulness at this early hour…).
Let’s say you have an application, which brings its own String, Math,
and Array functions. If you put them into the Module MyApplication, you
prevent collisions with Ruby’s String, Math, and Array functions.
Additionally, you can mixin these methods, while maintaining the ability
to inherit from the classes you have in your modules, if need be.
(You can inherit from Digest::MD5, for example.)
Also, only a module can include a module.
In short: It depends on your scenario.
Make the coupling between modules visible.
~ - The Elements of Programming Style (Kernighan & Plaugher)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----