← Graph

Polymorphic Aggregate

concept 2 connections

Implementation technique inspired by Szymon Kulec's functional aggregate blog series. Instead of a single issue class with a status field, there is one class per state (e.g. Issue, OpenIssue, ResolvedIssue, ClosedIssue, ReopenedIssue). Each class only defines the operations legal in that state and returns a new instance representing the next state; illegal operations raise. Event publishing and rebuilding from events move out of the aggregate into the command handler. Because different state classes no longer share the same interface, the author notes it is not strictly polymorphic; a later 'duck typing' implementation uses respond_to? to dispatch.

category
pattern
about
Polymorphic Aggregate concept
Second implementation has one class per state, inspired by Szymon Kulec's functional aggregates.
concept Polymorphic Aggregate
related_to
State Machine concept
Encodes state into the type system by using one class per state.

Provenance

Read by
9 extractions