# Java/C# "interface" in Ruby?

**URL:** <https://rubytalk.org/t/java-c-interface-in-ruby/20089>\
**Category:** ruby-talk\
**Created:** [11 August 2005 14:16 UTC](https://rubytalk.org/t/java-c-interface-in-ruby/20089 "2005-08-11T14:16:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Fitzgibbons1](https://avatars.discourse-cdn.com/v4/letter/p/aca169/32.png) [@Peter\_Fitzgibbons1](https://rubytalk.org/u/Peter_Fitzgibbons1)\
**Post date:** [11 August 2005 14:16 UTC](https://rubytalk.org/t/java-c-interface-in-ruby/20089/1 "2005-08-11T14:16:15Z")

</div>

Hello all,

This is a newbie question.  
Is there anything in Ruby that is equivalent to the Java/C# "interface".

Peter J. Fitzgibbons  
Applications Manager  
Lakewood Homes - "The American Dream Builder"(r)  
[Peter.Fitzgibbons@Lakewoodhomes.net](mailto:Peter.Fitzgibbons@Lakewoodhomes.net)  
(847) 884-8800

---

<div class="post-metadata">

**Author:** ![Austin\_Ziegler5](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/austin_ziegler5/32/1985_2.png) [@Austin\_Ziegler5](https://rubytalk.org/u/Austin_Ziegler5)\
**Post date:** [11 August 2005 14:18 UTC](https://rubytalk.org/t/java-c-interface-in-ruby/20089/2 "2005-08-11T14:18:53Z")

</div>

Depends. The standard answer is "thank ghu, no." There are some  
third-party implementations on the RAA, but you don't need them.

Mixins work better than "interfaces" ever will.

-austin

> **···**
>
> On 8/11/05, Peter Fitzgibbons \<Peter.Fitzgibbons@lakewoodhomes.net\> wrote:
> 
> > This is a newbie question.  
> > Is there anything in Ruby that is equivalent to the Java/C# "interface".
> 
> --  
> Austin Ziegler \* halostatue@gmail.com  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\* Alternate: austin@halostatue.ca

---

<div class="post-metadata">

**Author:** ![Florian\_Gross2](https://avatars.discourse-cdn.com/v4/letter/f/b4bc9f/32.png) [@Florian\_Gross2](https://rubytalk.org/u/Florian_Gross2)\
**Post date:** [14 August 2005 04:23 UTC](https://rubytalk.org/t/java-c-interface-in-ruby/20089/3 "2005-08-14T04:23:12Z")

</div>

Peter Fitzgibbons wrote:

> Is there anything in Ruby that is equivalent to the Java/C# "interface".

There is also [http://ruby-contract.rubyforge.org/](http://ruby-contract.rubyforge.org/) which tries to do this in a more Rubyish way. Perhaps it will be of interest to you.

---

<div class="post-metadata">

**Author:** ![Robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Robert](https://rubytalk.org/u/Robert)\
**Post date:** [11 August 2005 14:41 UTC](https://rubytalk.org/t/java-c-interface-in-ruby/20089/4 "2005-08-11T14:41:11Z")

</div>

Austin Ziegler wrote:

> > This is a newbie question.  
> > Is there anything in Ruby that is equivalent to the Java/C#  
> > "interface".
> 
> Depends. The standard answer is "thank ghu, no." There are some  
> third-party implementations on the RAA, but you don't need them.

Agree.

> Mixins work better than "interfaces" ever will.

I beg to differ here: mixin modules provide implementaitions while  
interfaces just define method signatures. IMHO mixin modules are better  
compared to multiple inheritance or reuse.

Kind regards

&nbsp;&nbsp;&nbsp;&nbsp;robert

> **···**
>
> > On 8/11/05, Peter Fitzgibbons \<Peter.Fitzgibbons@lakewoodhomes.net\> \> wrote:

---

<div class="post-metadata">

**Author:** ![James\_Edward\_Gray\_II](https://avatars.discourse-cdn.com/v4/letter/j/ea5d25/32.png) [@James\_Edward\_Gray\_II](https://rubytalk.org/u/James_Edward_Gray_II)\
**Post date:** [11 August 2005 14:53 UTC](https://rubytalk.org/t/java-c-interface-in-ruby/20089/5 "2005-08-11T14:53:53Z")

</div>

Yeah, I have to agree here. To me, the Ruby equivalent of interfaces would be Duck Typing.

James Edward Gray II

> **···**
>
> On Aug 11, 2005, at 9:41 AM, Robert Klemme wrote:
> 
> > > Mixins work better than "interfaces" ever will.
> > 
> > I beg to differ here: mixin modules provide implementaitions while  
> > interfaces just define method signatures. IMHO mixin modules are better  
> > compared to multiple inheritance or reuse.

---

<div class="post-metadata">

**Author:** ![Berger\_Daniel1](https://avatars.discourse-cdn.com/v4/letter/b/ecc23a/32.png) [@Berger\_Daniel1](https://rubytalk.org/u/Berger_Daniel1)\
**Post date:** [11 August 2005 14:59 UTC](https://rubytalk.org/t/java-c-interface-in-ruby/20089/6 "2005-08-11T14:59:22Z")

</div>

James Edward Gray II wrote:

> > > Mixins work better than "interfaces" ever will.
> > 
> > I beg to differ here: mixin modules provide implementaitions while  
> > interfaces just define method signatures. IMHO mixin modules are better  
> > compared to multiple inheritance or reuse.
> 
> Yeah, I have to agree here. To me, the Ruby equivalent of interfaces would be Duck Typing.
> 
> James Edward Gray II

I released "interface" on the RAA, mainly as proof that interfaces \*could\* be done in Ruby if you really wanted them. Note that I've never used it in actual production code.

The \*only\* Ruby library I've seen so far that \*might\* benefit from an interface is DBI, where you want to ensure that all of the DBD's have a common set of methods.

Even then, it's easy enough to simply document what methods should be defined and what they should do, then add a generic test suite which DBD writers can use to ensure correctness.

Regards,

Dan

> **···**
>
> > On Aug 11, 2005, at 9:41 AM, Robert Klemme wrote:
