Companions

Description

Companions are stateless modules that contain one or many pure functions that related to the same area. Companions should avoid side-effects and querying from the DB. Often, private methods in Actors can be extracted to Companions for easier testing and/or re-use across Actors.

Technology Status at Wunder

Adopt. Companions are a good way to extract and test complex logic without the boilerplate imposed by Actors.

Notes/Resources

  • Companions should be stateless, however you might find it convenient to initialize a companion with data. If this is needed, consider turning the companion into a simple Model. Otherwise, be pragmatic, but remember that ideally companions are stateless.
  • If you have an Actor which a) has a name like ‘Compute*’ b) never nacks c) has no side effects, you should consider converting the entire actor (or a substantial portion of it) to a Companion.