Internal Refactoring

For my 10-day visit to Tokyo, Kyoto, Nara, Hakone and Chiba (my brother-in-law’s wedding), I needed to refactor my internal progamming a bit to avoid OutOfMemoryExceptions.

// This class is package protected to avoid
// external programs messing up.class Brain {

public void handleEvent(MeetNewPersonEvent event) {
...  if (getLocation().equals(Locations.JAPAN)) {
 fireEvent(new BowEvent(event));
}}

public void handleEvent(BowEvent event) {
 // Avoid infinite loop.  The problem is the
// 'esteemed higher' part, the person
// for whom you're bowing may think the same.
 if (event.isPersonEsteemedHigher() && !event.hasBowedTooMuch()) {
 bow();
 } else {
 nod();
 }}

protected void bow() {
 lookSincere();
 smile();
 bendForward();
}

I also needed to reprogram the eating subroutines.

public void handleEvent(FeelingHungryEvent event) {
...  if (getLocation().equals(Locations.JAPAN)) {
 // This was a tricky one to handle,
// the implementation is left
// as an exercise to the reader.
uploadChopsticksRoutine();
}}

The RunForTrainEvent and especially the WaitForTrainEvent could be canceled out since public transportation is much better than the location I originally wrote it for (Belgium).

public void handleEvent(RunForTrainEvent event) {
 if (getLocation().equals(Locations.JAPAN)) {
   stopRunning();
   relax();
   Thread.sleep(5*Timer.MINUTE);
 }
}

Finally, I needed to handle the RunningNoseEvent (extends HasColdEvent) better.

public void handleEvent(RunningNoseEvent event) {
...  if (getLocation().equals(Locations.JAPAN)) {
 // Blowing your nose in public is NOT DONE
// in Japan.  This is considered
// a bit the same as burping.
// Public humiliation is your part when
// this is not checked.
 dipNose();
} else {
 blowNose();
}
}

protected Location getLocation() {
...
if (isCurrentLocationUnknown()) {
 if (bodyTallerThanMostOthers() && friendlyPeople()
       && metroEvery2Minutes()
       && dressCode.equals(Dresscodes.COSTUME)
       && eatingCode.equals(EatingCodes.SHOPSTICKS)) {
  return Locations.JAPAN;
  }
 }
}

} // End class

This is released under an Apache license. Please notify me if these changes are of any use to you.

One Response to “Internal Refactoring”

  1. bartdt says:

    That’s one fine piece of coding you got there :)

Leave a Reply