[erlang-questions] Erlang modelling question
Damien Morton
dmorton@REDACTED
Mon Jun 25 22:01:43 CEST 2007
Might have been a different conversation, but I think you were right
that the extensibility problem is the same as in the expression problem.
> Damien Morton <dmorton@REDACTED> wrote:
>
>> So your problem is one of code management - Darius, who frequents this
>> list sometimes, pointed out that its an instance of the expression
>> problem. see http://www.daimi.au.dk/~madst/tool/papers/expression.txt
>>
>
> That was a different conversation; I haven't really followed this one.
>
> FWIW, if the goal is to code mutable objects with inheritance, the
> most straightforward way seems to be with a process for each level of
> inheritance for each object: Java code like
>
> class Shape {
> int x, y;
> Shape(int x, int y) { this.x = x; this.y = y }
> void move(int dx, int dy) { x += dx; y += dy; }
> int getX() { return x; }
> }
>
> class Square extends Shape {
> int size;
> Square(int x, int y, int size) { Shape(x, y); this.size = size; }
> int getSize() { return size; }
> }
>
> might look like
>
> make_shape(X, Y) ->
> spawn(fun () -> shape(X, Y) end).
> shape(X, Y) ->
> receive
> {Self, {move, DX, DY}} -> shape(X + DX, Y + DY);
> {Self, {get_x, Cont}} -> Cont ! {Self, X}, shape(X, Y)
> end.
>
> make_square(X, Y, Size) ->
> Shape = make_shape(X, Y),
> spawn(fun () -> square(Shape, Size) end).
> square(Shape, Size) ->
> receive
> {Self, {get_size, Cont}} -> Cont ! Size, square(Shape, Size);
> Other -> Shape ! Other, square(Shape, Size)
> end.
>
> ask(Object, Message) ->
> Object ! {Object, Message}.
>
> (The Self argument is there to allow "superclass methods" to "call
> subclass methods", which I forgot to include an example of here.)
>
> This differs from the original post mapping classes to modules.
>
> Darius
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
>
>
More information about the erlang-questions
mailing list