As some of you know I’m currently preparing for a set of interviews for a job, and in the process of patching old work for show I came across an idea for a pattern I call the multi-blocking pattern.
What is it and why is it needed
The multi-blocking pattern provides an interface by which you can create classes which with methods that are both non-blocking and blocking. This allows you to - for example - write simple AI routines, for example here is a really simple Clue AI routine.
void aiTakeTurn () {
evaluatePlans ();
rollDice().complete();
evaluateRange();
moveToken().complete();
suggest().complete();
viewSuggestedCards();
if ( isSureOfEvidence () ) accuse ();
}
Explanation of example
So what happened there? Well if your game is event driven and [say] running over a network then you end up splitting a particular routine over to the event handlers, or coming up with potentially flawed schemes to provide for linear coding. All that happens is that the model-control interface methods return a handle to the operation that is carried out, where complete will wait until the completion conditions are met.
Sure it’s simple and isn’t exactly going to cure cancerous code bloat, but it’s got to be a useful approach to give to learner software engineers / computer scientists who are developing software that will probably have a need for both approaches. And it’s a pattern with a name!