Skip to content

Instantly share code, notes, and snippets.

@Afforess
Created November 4, 2012 19:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Afforess/4013360 to your computer and use it in GitHub Desktop.
Save Afforess/4013360 to your computer and use it in GitHub Desktop.
Death Cause Factory pattern
public enum DeathCause implements DeathCauseFactory {
DROWNING {
public Cause<?> buildCause(Entity victim, Entity killer) {
return new DrowningCause(victim);
}
},
FALLING {
public Cause<?> buildCause(Entity victim, Entity killer) {
//TODO
}
},
FIRE {
public Cause<?> buildCause(Entity victim, Entity killer) {
//TODO
}
},
ARROW {
public Cause<?> buildCause(Entity victim, Entity killer) {
return new ProjectileCause(victim, killer);
}
},
SKELETON,
...
;
}
interface DeathCauseFactory {
public Cause<?> buildCause(Entity victim, Entity killer);
}
class DrowningCause extends PlayerCause {
public DrowningCause(Player p) {
super(p);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment