Erlang Programming/Behaviors

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search

[edit] Behaviors

In Erlang, a behavior is a design pattern implemented in a module/library. It provides functionality in a fashion similar to inheritance in object-oriented programming or interfaces in Java. A number of callback functions must be defined for each behavior to work.

Examples of behaviors are:

  • client-server
  • event-handler
  • gen-server  :gen_server
  • hot-standby
  • keep-me-alive
  • supervision-tree
  • upgrade-handler
  • worker-supervisor

A behavior can be activated with the following code (note the 'u' in "behaviour"):

-behaviour(gen_server).