[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby's equivalent to Java's "interface"

Steve Quezadas

8/18/2007 9:44:00 PM

Please forgive this rather naive question, but it's a query that's
difficult to search for on google. In java, you can program to
interface. IE, in java, you can do:

public interface QuakeBehavior {
public void quack();
}

public class Quack implements QuckBehavior {
public void quack() {
System.out.println("Quack");
}
}

public class Squeek implements QuackBehavior {
public void quack() {
System.out.println("Squeek");
}
}

public class MuteQuack implements QuackBehavior {
public void quack() {
System.out.println("<< Silence >>");
}
}

I am learning about Design Patterns (which is a wonderful concept), but
I want to know the Ruby equivalent.

- steve
--
Posted via http://www.ruby-....

2 Answers

Robert Klemme

8/20/2007 8:10:00 AM

0

2007/8/19, david karapetyan <dkarapetyan@gmail.com>:
> Ruby modules also allow implementation details and I'm not sure if this is
> also true for java interfaces.

You can only define constants in a Java interface, no methods. A Ruby
module is by far not the equivalent to a Java interface. The short
answer is: there is no equivalent thing in Ruby. It is not needed
because of Ruby's dynamic nature (see Olivier's explanation).

Kind regards

robert

Mikkel Bruun

8/20/2007 11:07:00 AM

0

Robert Klemme wrote:
> 2007/8/19, david karapetyan <dkarapetyan@gmail.com>:
>> Ruby modules also allow implementation details and I'm not sure if this is
>> also true for java interfaces.
>
> You can only define constants in a Java interface, no methods. A Ruby
> module is by far not the equivalent to a Java interface. The short
> answer is: there is no equivalent thing in Ruby. It is not needed
> because of Ruby's dynamic nature (see Olivier's explanation).
>
> Kind regards
>
> robert

I second that...

--
Posted via http://www.ruby-....