I'm currently working on a computational physics code in Fortran. In summary, the code performs the following operations:
- Initialize
- Loop until done
- Advance solution over time
- Possibly write output
We want to support different physics modules, which solve different equations. I am thinking about the following design, which heavily relies on function pointers:
- Generate a template for a physics module, which contains definitions for the procedures that could be required, and stores pointers to these procedures. For example, there would be routines for initialization, time stepping and producing special output.
- Each physics module then defines its own procedures (and some data, which can conveniently be stored in a Fortran module)
- At the start of the code, one module is activated, which sets the template's pointers to the module's procedures
The motivation behind the above approach is that changing modules only requires a single change in the code (activate a different one), and that we keep the code relatively simple (no complex abstractions, inheritance and other object-oriented features).
Would this be considered a good design for a non object-oriented code?