The possibilities are many, but it'd typically be something like:
- building a command-line framework that abstracts out the parsing of options from the action. Then you can register an action with something like
opts.register("--on", new LightOnCommand())
.
- letting users drag and drop a sequence of actions to execute as a macro
- registering a callback when some event is triggered, like
on(Event.ENTER_ROOM, new LightOnCommand())
The general pattern here is that you've got one piece of the code responsible for figuring out that some action needs to be taken without knowing what that action is, and another piece of the code knows how to do an action but not when to do it.
For instance, in that first example, the opts
instance knows that when it sees a command line option --on, it should turn the lights on. But it knows this without actually knowing what "turn the lights on" means. In fact, it could well be that the opts instance came from a third-party library, so it can't know about lights. All it knows about is how to accociate actions (commands) with command-line options that it parses.