[erlang-questions] Custom behavior background information
Tue Sep 15 10:53:17 CEST 2015
A behaviour behaves in some specific way, and importantly the behaviour is
common enough (can be used repeatedly) to define it separately.
A behaviour exposes two sets of APIs. One set facilitates the communication
with external processes. The second one facilitates to define the behaviour
of it. The second set is also called call back functions.
The second set is like a contract that a call back module for a behaviour
should adhere to.
There may or may not a mapping between the two sets of APIs.
It is the responsibility of the behaviour defining module to call the
functions in the callback module when the triggering points are reached.
When you are using behaviours, you can use multiple of them meaningfully in
a single module. This is called cascading behaviours.
On Tue, Sep 15, 2015 at 1:34 PM, Frans Schneider <schneider@REDACTED>
> Hi list,
> I find myself repeating code in several gen_server and gen_fsm behavior
> based modules. These modules should all share about eight functions, all
> doing exactly the same thing. On top of these modules, more elaborate
> modules with common functions have to be defined, adding four or so
> functions. To me, this is looking like defining my own custom behaviors.
> I had a look at the implementation of the Erlang supervisor for extending
> the gen_server behavior which gives enough information to get something
> working. However, I have no glue how to extend the gen_fsm behavior and
> keep the interface to defining states in the new behavior.
> So, what I am looking for is some reference material on writing custom
> behaviors on top of what Erlang central and the OTP documentation offer.
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions