Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In C#/Java, the dependency inversion principle is often demonstrated by high-level classes that depends on an interface/abstraction (that it owns). Low-level classes will implement the interface, thus inverting the dependency.

I wonder, how is it applied in object-oriented languages with no interface? For example, I'm not an expert in Ruby, but it seems that in this language you can't define interfaces like in Java/.NET

share|improve this question
In Python (and I assume other languages you're asking about), every instance is an interface. See, for example: Take 2: Why we use SOLID in static languages and how we get the same functionality for cheap in dynamic languages – user16764 Apr 17 '13 at 2:32
up vote 6 down vote accepted

Even though you don't have explicit interfaces in dynamic languages, the dependency inversion principle can be followed by writing the client code against an abstract representation of the dependency, which the concrete "implementers" will adhere to via duck typing.

In a sense, that's the default in a dynamic language, and it could be argued that the dependency inversion principle is followed without any conscious effort. But, in practice it's worthwhile to consider the abstract representation of your concrete classes, to gain more insight into the domain, and to decouple from any implementation details that don't capture the essence of the abstraction.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.