Using interfaces for TakeDamage

Made with Miro. Thanks Claudio Grassi
  • If you change the name of any class, you will need to refactor it, and it’s not just about ‘rename’ it.
  • The code works fine for 1, 2 or 3 game objects, but in video games the reality is we can find hundreds of game objects that can execute TakeDamage, so the developer would be forced to write hundreds of else if statements
  • When a class inherits an interface, the class must implement all of the interface’s methods. That is called ‘contract
  • Each class is free to implement the interface’s methods as desired
Code improved. Thanks Michael Davis

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store