Quantcast
Channel: User Filip Milovanović - Software Engineering Stack Exchange
Viewing all articles
Browse latest Browse all 164

Comment by Filip Milovanović on Handling class specific behavior: polymorphism vs instanceof

$
0
0
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.

Viewing all articles
Browse latest Browse all 164

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>