Maybe Erlang is OO after all?

Chris Pressey <>
Mon Aug 25 18:12:13 CEST 2003


On Sat, 23 Aug 2003 03:39:28 +0200
Joachim Durchholz <> wrote:

> My experience with a language that supports DbC directly is that this
> is powerful enough to prevent idiocies like Dog.bark vs. Tree.bark
> (not that anybody in his right mind would make Dog a subclass of Tree
> or vice versa - this kind of problem is far less common than one might
> think).

Well, if you're lucky enough that the programmer didn't learn OO design
from a "how to program in C++" book, then, yes.  (how about if both Dog
and Tree are subclasses of Barkable... ewww)

In a sense, it's inheritance's job to "reign in" polymorphism a bit, and
in that light, languages like Erlang aren't as good at OO (I hesitate to
say that any language "is OO" or "is not OO") because you can happily
overload bark() like:

  bark(X) when record(X, dog) -> ...
  bark(X) when record(X, tree) -> ...

But when you do get into the case where you want an object that is a
combination of two disjunct classes, you do have a way to distinguish
between their methods: dog:bark(X) and tree:bark(X).  The underlying
implementation of X would have to be fairly inventive to allow it, but
I'm sure it could be done.

-Chris



More information about the erlang-questions mailing list