The other day I ran across an implementation of the equals method for a class in Smalltalk. At first glance, this method appeared to work but there was one problem. It assumed that the parameter was the same class as the receiver and immediately sent it messages that only instances of that class would understand. The problem here is that the equals method is used by a lot of code like Dictionaries and Sets. Since you can mix arbitrary objects in those collections, the equals methods must always return a valid answer irrespective of the class of the parameter. The proper thing to do is to check that the class of the parameter is the same as your own class and return false if it's not. Otherwise, you are likely to encounter unexpected problems.
Download