Static vs. Non-Static Methods

Video loading...

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:07
    In index.php, the 3 battle types are hard-coded right in the HTML.
  • 0:12
    So what happens if we decide to add a fourth battle type to BattleManager?
  • 0:17
    No problem. Add a new constant, then update the battle method logic for whatever cool thing this new type does.
  • 0:26
    But surprise, if we forget to also add the new type to index.php then nobody’s going to be able to use it.
  • 0:34
    Really, I’d prefer BattleManager to be completely in charge of the battle types
  • 0:39
    so that it’s the only file I need to touch when something changes.
  • 0:44
    To do that, create a new function in BattleManager that will return all the types and their descriptions.
  • 0:51
    Call it public function getAllBattleTypesWithDescription.
  • 0:58
    Here return an array with the type as the key
  • 1:01
    and the description that should be used in the dropdown as the value.
Loading ...