Behaviours

Vance Shipley vances@REDACTED
Sun Sep 8 23:19:18 CEST 2002


I can remember struggling to understand the "magic" of the standard
behaviours.  The light really came on for me when I realized the
distinction between modules and processes.  The two are pretty much
unrelated.  A module may be executed by many processes and a process
may execute code from many modules.  The documentation (for gen_fsm
in this case) has the following description which, while being quite
useful, can confuse this issue:

	A gen_fsm assumes all specific parts to be located in a
	callback module exporting a pre-defined set of functions.
	The relationship between the behaviour functions and the
	callback functions can be illustrated as follows:

	gen_fsm module                    Callback module
	--------------                    ---------------
	gen_fsm:start_link                -----> Module:init/1
	
	gen_fsm:send_event                -----> Module:StateName/2
	
	gen_fsm:send_all_state_event      -----> Module:handle_event/3
	
	gen_fsm:sync_send_event           -----> Module:StateName/3
	
	gen_fsm:sync_send_all_state_event -----> Module:handle_sync_event/4
	
	-                                 -----> Module:handle_info/3
	
	-                                 -----> Module:terminate/3
	
	-                                 -----> Module:code_change/4
	    
	
While there is nothing wrong with this description my read of it 
suggested there were messages being passed between processes.  When I
realized that using a behaviour simply meant that you were including 
code from a standard library into your own I truly understood them.

	-Vance



More information about the erlang-questions mailing list