I am trying to improve a Java project that uses many large case statements. In cases where the case statement is used, it is used to process an event that has an attribute associated with it. For instance:
public void jumpOverWall(int wallID) { switch (wallID) { case 0: case 1213: case 2123: case 3123: case 4123: } }
The numbers are not consecutive, and all require another action that needs to be performed - for example, "You cannot jump over this wall" or moving a character to a predetermined position. There are very few cases where the answer to this case follows a given pattern. I mean, switch statements do not follow a pattern that allows you to use code similar to:
public void jumpOverWall(int wallID) { someArray[1213] = 10; someArray[3123] = 20; if (playerJumpingSkill > someArray[wallID]) {
Therefore, I wonder how best to handle these "events." The whole idea of ββthe "event handler" style system is what appeals to me, but I'm stuck on how to implement it (or the best solution to the problem). Too many "events" (in my opinion) for each individual class.
Is there a method / project for hooking events? Will this be applicable / work. I would look at an easy connection method, for example:
hookEvent(1213, new SomeInterface() { boolean eventOK() {
Then will these βhooksβ be checked and called up?
source share