jueves, 12 de agosto de 2010

Erlang: Mapping Objects Classes to Actors Model

You can "map" an object class to actor. Lets see a simple example:

public class myClass
{
   private string myProperty;

   public myClass(string argInit) {
      myProperty = argInit;
   }

   public myMethod(string arg1, int arg2) {
      //do something
      myProperty = arg1 + arg2.toString();
   }
}

The actor (process with Erlang) is:

myClass(myProperty) ->
   receive
      {myMethod, Arg1, Arg2 } ->
         myClass(Arg1 ++ Arg2)
   end.

And it's "constructor" is the spawn of process:

spawn( myClass, [argInit ]).

Thus, an object's method (OOP) is an actor's message. Like UML sequence diagrams.

No hay comentarios: