I do not have an exact drawing to explain this, but I have in this chapter , and after I have shown how to create gen_server, starting with the principles of abstraction that lie behind it.
To help with individual components:
implementation of behavior
The behavior itself is a bit like the one shown in the previous chapter I. This is a module with many functions that perform all the common things for you: receiving messages, defining functions and hidden protocols for communication, etc. The OTP extended material contains special types of messages used to update software, as well as special code for trace parameters.
container behavior
I'm not sure what it should be. Maybe just a module named behavior?
behavior interface
In the same module, your implementation of the behavior, you must define the function behaviour_info/1 . This function will let the Erlang compiler know that some callbacks are expected from any module with -behaviour(SomeModuleName) . SomeModuleName equivalent to the file SomeModuleName.erl (and .beam ), which contains the implementation and function behaviour_info.
callback module
A module that will contain all the specific code, processing all user materials.
callback functions
Everything that is not shared must be delegated to the callback module in the form of YourModule:SomeCall(Args) . This is provided by your module, which has the line -behaviour(gen_server). .
API Functions
The callback module has two interfaces if you want: one for the behavior of gen_server (init / 0, handle_call / 3, handle_info / 2, handle_cast / 2, terminate / 2, code_change / 3) and one for the user (start the server, send some information, ask for some information back).
I could try to describe it that way
--------------------------------------------------------------------- | some process | server process | ------------------------+-------------------------------------------- [client] | [callback] : [behaviour] | : callback:start >-------|---------------------:--> starting the process | : V | : | | init() <-----:-----------` | | : | `-----------:------> initial state {ok, Pid} <----------|---------------------:----------,/ | : callback:store >------|---------------------:--> handles message (calls the process) | (formats msg) : V | : | | handle_call() <--:-----------` | | : | `----------:--> updates state, sends reply | : V | : | gets result <--------|---------------------:--------` | :
All common parts are to the right of the server process, as part of the behavior, and all defined parts are to the left (callback). The client uses the callback module API to contact the server process and have an effect on it.
You should see behavior as a kind of very general segment of code that sometimes refuses the flow of execution (to get more precise details, such as receiving and sending messages) to a specific code (how to respond to these messages).
Hope this helps.