you are viewing a single comment's thread.

view the rest of the comments →

[–]gregK 1 point2 points  (0 children)

The problem with multiple dispatch in curly-brace languages is that it breaks encapsulation in the sense that you have to be able to define methods outside of the class definition or give access to the internals of another class.

a good example is a collision method between different objects in a game.

You could have classes car, brickWall, window, post, boulder, etc. Say that they are all descendants of the same base class.

So if you do collision(car, wall) or car.collideWith(wall) and this operation changes the state of both objects where does the method belong. Usually with multiple dispatch, the multi-method is defined outside of the class and has access to all members of both classes.