Be aware that your two options (which may also appear in other guises) involve a tradeoff: with polymorphism, the abstract interface gets harder to change the more client and component classes you have, as you have to update every component. But beyond that, you can add new kinds of components easily. With instanceof, adding new kinds of components is a pain, because any client can pass in the new component to any handler, so all handlers must be updated to support it. But assuming the set of components is stable, adding a new handler is fairly easy and changes are confined to one function.
↧