interfaceoopdynamic-languages

Why do dynamic languages like Ruby and Python not have the concept of interfaces like in Java or C#?


To my surprise as I am developing more interest towards dynamic languages like Ruby and Python. The claim is that they are 100% object oriented but as I read on several basic concepts like interfaces, method overloading, operator overloading are missing. Is it somehow in-built under the cover or do these languages just not need it? If the latter is true are, they 100% object oriented?

EDIT: Based on some answers I see that overloading is available in both Python and Ruby, is it the case in Ruby 1.8.6 and Python 2.5.2 ??


Solution

  • Thanks to late binding, they do not need it. In Java/C#, interfaces are used to declare that some class has certain methods and it is checked during compile time; in Python, whether a method exists is checked during runtime.

    Method overloading in Python does work:

    >>> class A:
    ...  def foo(self):
    ...    return "A"
    ...
    >>> class B(A):
    ...  def foo(self):
    ...    return "B"
    ...
    >>> B().foo()
    'B'
    

    Are they object-oriented? I'd say yes. It's more of an approach thing rather than if any concrete language has feature X or feature Y.