Ruby's equivalent to Java's "interface"

S

Steve Quezadas

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
 
R

Robert Klemme

2007/8/19 said:
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
 
M

Mikkel Bruun

Robert said:
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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top