EdUarDo <eduardo.yanezNOSPAM / NOSPAMgmail.com> writes:

> Hi all again :),
>
> How could I implement this model?
>
> Window <>--------------------- Button
>                                   ^
>                                   |
>                                   |
>                           -----------------
>                           |               |
>                        BigButton      LittleButton
>
>
> Being 'Button' an abstract class or an interface.
> I mean, how do I define an interface? Must I use modules?

In Ruby, modules are like abstract classes except you can
inherit from any number of them; or like interfaces except
you can put method bodies in them.

Anyway, because Ruby is not statically typed, you never have
to define an interface before using it.  As long as you
don't call a method °∆foo°« on an object that does not
understand °∆foo°«, Ruby doesn't care.

This is what people mean when they talk about °»duck typing°…:
there are no interfaces except the *actual* interfaces.

If the two kinds of buttons have some common functionality,
put that into Button; if they don't, you don't even have to
define the Button class, because it would serve no purpose.

   class BigButton
     def push ; puts "Hey, don't push me!" end
   end

   class LittleButton
     def push ; puts "*whimper*" end
   end

   def abuse_button(button)
     5.times { button.push }
   end

-- 
Daniel Brockman <daniel / brockman.se>

    So really, we all have to ask ourselves:
    Am I waiting for RMS to do this?   --TTN.