[erlang-questions] Callbacks with record name == module name
Zoltan Lajos Kis
kiszl@REDACTED
Wed Dec 30 16:54:40 CET 2009
You could abstract away the parts where you are getting into the guts.
foo(Id) ->
{ok, V} = myapp_get_by_id(Id),
Class = class_of(V),
Class:foo(V).
class_of(V) ->
element(1,V).
You can also give parametrized modules a try. It has a more OO L&F.
foo(Id) ->
Obj = get_obj_by_id(Id),
Obj:foo().
get_obj_by_id(Id) ->
{ok, V} = myapp_get_by_id(Id),
Class = class_of(V),
Class:new(V).
Z.
Taru Karttunen wrote:
> Hello
>
> Is it sensible to write code with callbacks for different "object"
> types like:
>
> foo(Id) ->
> {ok, V} = myapp_get_by_id(Id),
> (element(1,V)):foo(V).
>
> Or is there a more idiomatic way of handling this?
>
> - Taru Karttunen
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>
More information about the erlang-questions
mailing list