[munich-lisp] multimethods, generic functions, multiple dispatch, ...

Andreas Hauser andy at splashground.de
Sat Sep 10 07:50:35 UTC 2005


Christian.Schuhegger wrote @ Sat, 10 Sep 2005 08:58:48 +0200:

You seem to have forgotten to show the actual Lisp code.

> class Triangle implements Shape {
>      public boolean collidesWith(Shape other) {
> 	other.collidesWithTriangle(this);
>      }
>      ...;
>      public boolean collidesWithCircle(Circle s) {...;}
>      public boolean collidesWithSquare(Square s) {...;}
>      ...;
> }

While having methods with the same name but different signatures is
certainly something i like, maybe in this case you just have problems
with the objects you designed. I guess, we all know Java is limited,
but let's not forget, they call it a feature.


class Triangle implements Shape
{
     public 2Dspace space()
     {
         2DSpace my_space = xy[screen.x_dim][screen.y_dim];
         // fill the matrix with pixels the Triangle occuppies
         return my_space;
     }
     public boolean collidesWith(Shape other)
     {
         return overlap(other.space, this.space);
     }
}

So first, generalize the properties of your objects and then let them
interact. I would also say that colliding and especially overlap()
is something that the Object World should do.


Andy



More information about the munich-lisp mailing list