An interface function is a public entry point that lets clients start or use a component without knowing how it creates processes or communicates through messages. In a server-process module, clients call functions such as start/0, while private implementation functions run the message loop in another process. section 5.3.1
The boundary separates client-facing operations from server behavior. Interface functions execute in the caller process and hide the communication protocol; implementation functions usually remain private and execute in the server process. section 5.3.1
A practical interface-function design typically provides:
- A start function that spawns the long-running server process. section 5.3.1
- Public operations that encode requests and delegate communication to the server. section 5.3.1
- Helper functions that keep clients unaware of a generic server abstraction and its callbacks. section 6.1.3
Wrapping a generic server
KeyValueStore exposes start/0, put/3, and get/2. These functions call ServerProcess.start/1 and ServerProcess.call/2, while init/0 and handle_call/2 remain callback functions used internally by the generic process. section 6.1.3
Listing 6.5 Wrapping ServerProcess function calls (server_process.ex)
defmodule KeyValueStore do
def start do
ServerProcess.start(KeyValueStore)
end
def put(pid, key, value) do
ServerProcess.call(pid, {:put, key, value})
end
def get(pid, key) do
ServerProcess.call(pid, {:get, key})
end
...
end
Shows the before-and-after boundary where application-specific functions wrap generic server-process calls. section 6.1.3
