Extensive use of instanceof

Due to the Hierarchy Structure of the Type, the natural way to represent it was as class hierarchy. However, this led to heavy use of instanceof which I guess it becomes a way cumbersome. I am looking for a solution to mitigate the problem and thought about the visitor pattern, I am not really sure if it would make sense to use this design pattern especially since our problem is not related to extensibility.

You might want to consider what you are actually trying to figure out at the places you are using instanceof. Perhaps you can recognize common functionality and pull this into a member function that is appropiately overridden.

As was already mentioned, sometimes, using instanceof is unavoidable. The tutor implementation uses it about 15 times (auto-generated equals methods included, without it that’s just 8 or so), but half of them could be eliminated by doing some quick refactoring.