Skip to content

Reusing event interpreter code

bekaus edited this page Oct 20, 2011 · 1 revision

The event switch implements event redirection in a way, that completely isolates event interpreters from each other. Volumina can therefore be extended easily with new interaction modes.

Most interaction modes so far are very similar to the basic navigation mode with some additions like selecting objects or controlling drawing. To avoid code duplication we have to reuse the navigation interpreter code. "Composing interpreters" currently seems to be the soundest solution. The other two ideas of "deriving from an interpreter" and the Qt state machine framework have severe drawbacks in comparison.

Deriving from an interpreter

  • violates the is-a principle (dangerous when asserting types)
  • violates one class - one responsibility (exposes methods, that are part of a foreign interpreter and not owned be the implementation)
  • Overriding methods changes the original semantics, that can lead to bugs like inconsistent state of the base interpreter

Using Qt state machine framework

  • theoretically clean solution
  • very much overhead in relation to the trivial interpreters implemented so far
  • code hard to understand for programmers, that don't know the framework (* keep in mind for later use)

Composing interpreters

  • simple to implement and to understand
  • hides the involvement of other interpreters (therefore allows changes of the implementation later)
  • state machine diagrams can be used nevertheless to document the control flow of the interpreter