Reflection in Erlang.

Héctor Rivas Gándara keymon@REDACTED
Thu Jan 27 00:01:05 CET 2005


El Miércoles, 26 de Enero de 2005 17:43, Fredrik Linder escribió:

> One of my favourite usages of the behaviour feature is to write an
> behaviour definition module and then write a behaviour implementation in
> another module. The behaviour definition module *also* implement the
> exported functions, but with a Module argument as the first argument.

> Using this design you could have the adaptor:getStub(...) return
> my_behaviour_implementation and later use that to make the calls.

I wan't to wrap  objects from other language, so the problem is how to 
dinamicly impersonate an object with an arbitrary interface in Erlang.  I  
can solve this using the simple call:

adaptor:callMethod(Obj, "method1", Args).

but I was looking for some "Sugar Syntax". The ideal was something like:

Obj:method1(arg1, arg2).

But I known, Erlang is not an OO language :)

> (2) Dynamically create a module following these steps:
> Have the adaptor:createInstance("anInterfaceId") function (exactly how to
> can be found in the archives of this mailing list):
> 1 - Write the code of the module relating to the specified interface *with*
> state information into a file. 2 - Compile that module (file) in run-time
> using the compile module. 3 - Load that module into the desired node(s).
> 4 - Initialize the module if necessary (especially if each object also is a
> process). 5 - Return the module name (as an atom).

I think that this produces excessive overhead. I'll have a lot of objects.

-- 
Greets



More information about the erlang-questions mailing list