Author note: This post is old and I don’t necessarily agree with everything here.
Still, the code is fun and I get a modest number of visitors for this post.
Without further ado…
I was reading Object Design a few months back and came upon an example illustrating double dispatch.
The example was showing a simple way to model Rock, Paper, Scissors. Here is the code translated to Ruby from Java:
Programmers with some experience with metaprogramming may instinctively feel uneasy with this code. I mean, it looks like a pattern. And we know that if we wished to extend the game, then we’re obligated to add another boxy class with all of those silly loses_to... methods.