← Graph

Prefer class-method services over stateful service objects

takeaway 2 connections

When a service is implemented as an instantiable class, someone inexperienced will eventually add state to it. Implement services as class methods (or a single method) instead — state becomes structurally inaccessible short of using globals. Ivan derived this from rewriting an interactor-gem multi-class scenario into a four-line method and concluding the extra machinery added no value.

type
recommendation
takeaway Prefer class-method services over stateful service objects
about
Concrete articulation of the stateless-service pattern.
takeaway Prefer class-method services over stateful service objects
from_talk
Takeaway from the interactor-to-four-lines anecdote.

Provenance

Read by
9 extractions