I’m developing a Matlab GUI for a scientific computing application and need to plot fairly heavy intermediate results.
Currently, the computation is represented as a function. The GUI accepts user input and passes it to the computation function, which returns the final data results.
Architecturally, the GUI incorporates a view and controller class. Main initializes these objects, in addition to defining the computation function, which lives in a sourced file.
Now, because I need to plot intermediate results, I’m trying to figure out the best way to create separation of concerns between the computation logic and plotting. The physical display of intermediate results to the user does not need to take place until the computations are completed.
My instincts are that the computation functions should not know that they’re being plotted.
Ideas so far:
- Computation logic accepts UI axes handles as an input argument, plotting takes place inside the computation logic. This appears to violate separation of concerns.
- Computation logic returns a data structure containing intermediate results. The GUI is responsible for binding the data to GUI plots. I don’t like this, as it seems cumbersome to keep all the intermediate data around.
- I create a plotter object, which is initialized in main() and can be configured (e.g., turned on or off). During the computation procedure, the computation function calls a plotter method that generates the needed plots and discards the data. The plotting logic in the computation function is reduced to a single plotter method call, but it still exists. This is analogous to idiomatic solutions for logging in large applications.
- The computation now lives inside a class, with intermediate results as a continuously overwritten member variable. The completion of an intermediate result triggers an event, a plotter object listens for that event and accesses/plots the computation class’s intermediate result member variable. This seems most fully separated, as now the computation logic has no knowledge in its code to being plotted.
Ultimately, the computation is generating and discarding intermediate results that need to be captured and processed by another object, and I need some way of interspersing additional logic without modifying the original function.
Any other ideas? This is being done in Matlab, but if there’s a conventional way of tackling this in other languages, I’d still love to learn about it.
This problem appears very analogous to organizing logging code, as in this question. However, while it seems widely accepted that logging statements intersperse business logic, it’s unclear if plotting demands stronger separation, or if inseparably it should itself be considered business logic and contained within the computation code.