[erlang-questions] OO programming style in Erlang?

Thomas Lindgren <>
Wed Jan 24 14:23:29 CET 2007


--- Ladislav Lenart <> wrote:

> And this I guess is the part I have a psychological
> problem with.
> I am used to an idiom where data are hidden behind
> an interface
> that operates on them. This decouples user of the
> module from
> having to deal with internals of that module. But as
> you described
> it, data are exposed in Erlang. So each time you
> want to change the
> representation (add something because of one new
> function), you have
> to revisit many of the existing functions that
> operate on that
> representation. This seems more than a few changes
> to me...

The classic approach is to use abstract data types,
ADTs: provide an API for operating on the data, and
implement the operations in a module. The actual data
representation is thus safely stored in a single place
and can be changed without disturbing the clients.
'dict' is a fairly good example of working in this
style. I use it all the time for some kinds of data.

Erlang also provides pattern matching, which
usually(*) exposes the internals of your data, and
records, which provide a weak sort of abstraction. In
some cases, using these leads to more concise code
than ADTs and so it may after all be better to go that
way. But, as you seem to be aware, there may also be
future headaches in doing so.

Best,
Thomas

(*) Richard O'Keefe has proposed a way to combine
hiding and pattern matching in Erlang, but it hasn't
been implemented as far as I know.


 
____________________________________________________________________________________
The fish are biting. 
Get more visitors on your site using Yahoo! Search Marketing.
http://searchmarketing.yahoo.com/arp/sponsoredsearch_v2.php



More information about the erlang-questions mailing list