I’ve had trouble managing dependencies between modules and I’m looking for advice on what to do in a situation that I often come across. To make it easier to discuss I’m going to use a (simplified) example from my game.
In my game I have a
Menu module and a
Model module (which contains the top level Model). The
Menu has a
MenuModel for storing state that’s only relevant while in the user is in the menu. The problem here is that
Menu.view uses both
Model.Model. So I end up with a dependency loop. The solutions I can think of are to either:
- “Component-ize” Menu so that it has it’s own
updatefunction, and a
Configextension record that has all the fields that
I don’t like the first solution because now any function in my app can modify
MenuModel in potentially invalid ways. When the
MenuModel was in
Menu I could make it opaque and only a small number of functions would have access to its internals*.
I don’t like the second solution either because a lot of extra wiring has to be done to make
Menu work with the rest of the app. Sometimes that’s worthwhile if the component is used in multiple places in my game, but the
Menu is only used once.
Are there better solutions I have overlooked?
*I can still make MenuModel opaque in Model and then add all the functions that can modify it to the Model as well, but if I use this solution every time I run into a dependency loop then I end up with a Model.elm file that’s ususably large.