Thread: [Discussion] Interest in a Java Pokemon API?
View Single Post
  #42    
Old March 28th, 2013 (07:30 PM).
UnderMybrella's Avatar
UnderMybrella UnderMybrella is offline
Some Game Developer
 
Join Date: Jan 2011
Location: Atlantis
Gender: Male
Nature: Calm
Posts: 268
I'm actually creating a Mystery Dungeon kit, in a similar format. As for interfaces, I learnt the main use of them when creating another game. This is where Interfaces > Classes.

Say we have an Ability. Ability is a class. Then, we have a Pokemon, with it's updateState method.
Ability has a method. This method is called effect(), and receives a Pokemon. It then does everything it needs to.

Now. Let's say there are 10 abilities. We would like to avoid creating 600+ files for Pokemon, so we have 1 generic class that will do everything for us (Maybe some other helper classes too).

The updateState method looks something like this:
Spoiler:

public void updateState(String state)
{
Ability a1 = this.primaryAbility;
if(ability instanceof AOvergrow)
(a1(AOvergrow)).effect();
... etc
//And then again for secondary effect
}


This is ridiculous. For every ability in the game, we add an extra 2 lines, and, with secondary abilities, that's 4 lines per ability!
However, with Ability as an interface, it's one line!
this.primaryAbility.effect()!
Sure, more classes, but you could narrow them down. You'd find a way
__________________
The Monoball Challenge - Have you got what it takes to catch 'em all, but with only one type of Pokéball? http://www.pokecommunity.com/showthread.php?p=7889482
Reply With Quote