[munich-lisp] multimethods, generic functions, multiple dispatch, ...
Christian Schuhegger
Christian.Schuhegger at gmx.de
Sat Sep 10 08:07:09 UTC 2005
Andreas Hauser wrote:
> Christian.Schuhegger wrote @ Sat, 10 Sep 2005 08:58:48 +0200:
>
> You seem to have forgotten to show the actual Lisp code.
sorry :)
(defmethod do-shapes-collide-p ((shape1 Triangle) (shape2 Circle))
(...))
(defmethod do-shapes-collide-p ((shape1 Circle) (shape2 Triangle))
(do-shapes-collide-p shape2 shape1))
(defmethod do-shapes-collide-p ((shape1 Triange) (shape2 Square))
(...))
...
>
>
>>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.
and what do you do if you talk about vector objects and not pixel objects :)
--
Christian Schuhegger
http://www.el-chef.de/
More information about the munich-lisp
mailing list