Dave discusses an alternate component-based approach to writing GenServers. This consists of modules in three files:
- A public API to hide the GenServer complexity.
- The GenServer interface.
- Implementatation.
The public API is just a wrapper to the GenServer functions and the GenServer functions are just a wrapper to the implementation. This hides the GenServer call/cast complexity and isolates the implementation.
I like this approach, but think that breaking it into three files is too complex. If the public API is only a wrapper to the GenServer API and the GenServer API is only a wrapper to the implementation, we can easily put them into a single file.
My approach implements the GenServer in two files:
- Public API which calls the GenServer functions.
- Implementation