In Ruby, what is the equivalent to an interface in C#?

后端 未结 6 962
轮回少年
轮回少年 2021-01-01 12:31

I\'m currently trying to learn Ruby and I\'m trying to understand more about what it offers in terms of encapsulation and contracts.

In C# a contract can be defined

6条回答
  •  借酒劲吻你
    2021-01-01 12:51

    Interfaces are usually introduced to static typed OO languages in order to make up for lack of multiple inheritance. In other words, they are more of a necessary evil than something useful per se.

    Ruby, on the other hand:

    1. Is dynamically typed language with "duck typing", so if you want to call method foo on two objects, they don't need to neither inherit same ancestor class, nor implement the same interface.
    2. Supports multiple inheritance through concept of mixins, again no need for interfaces here.

提交回复
热议问题