Design Patterns for Erlang
Chris Pressey
cpressey@REDACTED
Wed Feb 14 22:19:56 CET 2001
"Juan A. Suárez Romero" wrote:
> Hi all.
> I've been programming with Java during last years, but at present I'm learning
> Erlang, and it seems very powerful.
> In the development of my Java applications I used the Erich Gamma's
> Design Patterns book; but the patterns that appear in it are very based on
> inheritance and polymorphism, issues that Erlang hasn't.
> Somebody knows where could I find such patterns (or similar patterns) but
> applied to Erlang?
I'm still a newbie to Erlang, but I've worked "across paradigms" before,
touching on subjects such as patterns and equivalent notions in
different paradigms. Here is how I see it (which hopefully isn't too
misinformed):
Instead of inheritance, Erlang uses behaviours (functions which take
callback functions, as I understand it.) In this way a general module
can provide an interface & framework, while specific functionality can
be delegated to another module. Delegation is a little more general
than inheritance, in that it doesn't denote identity (if A is a subclass
of B, then A is a B; if A is a delegate of B, A is not necessarily a B.)
Polymorphism is a slightly different matter. Erlang functions are
polymorphic in the sense that they can accept arguments of differing
types, like polymorphic functions in ML. But this isn't quite the same
as the object-oriented sense. However, if the crucial aspect of
polymorphism is that a single reference (or name) can refer to more than
one kind of thing, then Erlang supports this, in a way, with dynamic
typing.
Either way, Erlang is not an object-oriented language, so putting either
of these concepts into an Erlang program will require some explicit
coding, although not as much as in a language such as C.
I've wondered if, using structures and funs, one could build a more
classically object-oriented structure into an Erlang program, storing
funs in structure fields and calling them 'virtual methods;' but it
seems like it might be just a waste of time.
I'm pretty sure that delegation and polymorphic functions give the
programmer nearly the same amount of expressive power as inheritance and
polymorphic objects. I'm not certain that they generate the same
patterns, but (at an educated guess) they are not too dissimilar, that
with some work, they can be applied.
Like I said, I'm still pretty new to Erlang, so I might be wrong in the
above analysis, and if some really experienced Erlang guru contradicts
it, believe them instead!
_chris
--
Change rules.
Share and Enjoy on Cat's Eye Technologies' Electronic Mailing List
http://www.catseye.mb.ca/list.html
More information about the erlang-questions
mailing list