Beyond Fat Models: An Introduction to DCI
Traditional object-oriented design encourages placing behaviour directly on the classes that hold state. Over time, an Account or Order class accumulates methods from dozens of unrelated use cases – billing, auditing, notifications, reporting – until no engineer can reason about the object as a whole.
Data, Context, and Interaction (DCI) solves this by separating code along two axes: what the system is (stable data models) and what the system does (runtime use cases).
The Four Building Blocks
DCI organises every application around four explicit concepts:
- Data. Dumb domain objects that represent the user’s mental model of core entities. Data objects enforce local invariants (such as a balance never dropping below zero) and know nothing about use cases.
- Roles. Stateless interfaces or behaviour sets that describe how an entity participates in a specific scenario. In a transfer, one account plays the
SourceAccountrole and another plays theDestinationAccountrole. - Context. A dedicated module or object representing a single business use case. The Context instantiates for the duration of the workflow, binds Data objects to Roles, and triggers the interaction.
- Interaction. The algorithms executed between Roles inside a Context. Because all role methods live together inside the Context, the entire business workflow reads sequentially in one place.
Solving Self-Schizophrenia
In classic OOP, splitting behaviour across mixins, decorators, or wrapper classes introduces self-schizophrenia: this or self inside a wrapper points to the wrapper rather than the underlying domain object, breaking object identity and state access.
DCI avoids this by binding roles directly to domain objects only within the scope of an active Context. Outside the Context, an Account is just an Account. Inside MoneyTransferContext, it acts strictly through its assigned role.
Why Nim Fits Naturally
Most class-based languages struggle to express DCI because methods are permanently welded to class definitions. Nim separates object definitions from proc procedures by default. Combined with Uniform Function Call Syntax (UFCS) – which lets proc withdraw(self: SourceAccount, amount: int) be called as source.withdraw(amount) – Nim expresses DCI idioms directly using built-in language primitives.
