Simply Broken

← Functional, Object-Oriented and Domain-Driven Design, Combined

Version 1, 14 November 2026

Three ideas, one small system

Functional programming, object-oriented programming and domain-driven design answer three different questions, so they fit in one style. They conflict in one place only: the object that changes itself.

Border: Donations The words inside: Pledge, Donation, Match Shell load save publish Web form Database Email Core state + command gives an event
One small system that takes donations. Each of the three ideas owns a different part of it. Choose an idea to see its part.
The example on this page is a donation with a match: a donor pledges 100 dollars, and a sponsor doubles it.

Each idea answers a different question

This is why they combine. Two ideas fight only when they answer the same question in two ways.

Domain-driven design

What do we model, and where are the borders?

The code uses the words of the business. A border marks where a word keeps one meaning.

Functional programming

How do we calculate a decision?

Data does not change. A function takes input and returns output, and it does nothing else.

Object-oriented programming

How do we pack the parts and hide the details?

A part shows a small interface and hides the rest. Two parts with the same interface can replace each other.

Try it: send a command to the core

The core is one function. It reads the current state and a command, and it returns a decision. Press a command and read the four steps.

Donation 4417 is now Pledged 100 dollars, match 2x
  1. 1. Shell loadsWaiting for a command.
  2. 2. Core decidesNothing yet.
  3. 3. Shell savesNothing yet.
  4. 4. Shell publishesNothing yet.
Events so far
None.
Try to refund a pledge, or to receive a payment two times. The core answers with a rejection, and the shell saves nothing. A rejection is an answer, not a crash.

The twelve words to know

Each word has a plain meaning and one example from the donation. Open a word to see it in code.

From domain-driven design

Bounded context

A border inside which each word has one meaning.

In fundraising, a donation is a gift with a match. In accounting, a donation is a receipt line with a tax status. These are two contexts. Each one has its own model, and neither one bends to fit the other.

You find a border when the same word changes meaning in one conversation.

Ubiquitous language

The business words are the code words.

The fundraiser says pledge, receive and refund. The code has Pledged, receive and DonationRefunded. Nobody translates between the meeting and the file.

Value object

A small thing known only by its value. It never changes.

100 dollars is a value. Two amounts of 100 dollars are equal, and no one edits one of them. A new amount is a new value.

@dataclass(frozen=True)
class Money:
    amount: Decimal
    currency: str

    def __post_init__(self):
        if self.amount < 0:
            raise ValueError("Money cannot be negative")

Entity

A thing with an identity that continues through change.

Donation 4417 is the same donation when it is a pledge, when it is received and when it is refunded. Its number is its identity. Its status is its state.

Aggregate

A group of things that must stay correct together, changed through one door.

A donation and its match are one aggregate. No code can change the match and skip the rules of the donation. In the combined style, the one door is one function.

Domain event

A fact that occurred, named in the past tense.

PaymentReceived. DonationRefunded. A fact cannot change, so an event is data that never changes.

@dataclass(frozen=True)
class PaymentReceived:
    donation_id: int
    amount: Money
    matched: Money

From functional programming

Pure function

The same input always gives the same output. It touches nothing outside itself.

The match calculation is pure. It does not read the clock, the database or the network. To test it, you call it.

def matched_total(amount: Money, multiplier: int) -> Money:
    return Money(amount.amount * multiplier, amount.currency)

Immutable data

Data that does not change after it is made. A change makes a new copy.

When a pledge is received, the code does not edit the pledge. It makes a new Received value. The old pledge is still there, and no other code was surprised by a change.

Side effect

Anything that touches the world outside the function.

A database write, an email, a payment call, a read of the clock. A program needs them, so the style does not remove them. It moves them to the edge, into the shell.

From object-oriented programming

Encapsulation

A part protects its own rules. No outside code can put it in a wrong state.

Negative money cannot exist, because Money refuses to be made with a negative amount. Functional programming gets the same result with a function that checks and then builds. The two ideas agree here.

Interface, also called a port

A plug shape. It says what a part can do and hides how.

The shell needs to load and save a donation. It does not need to know which database does the work.

class DonationStore(Protocol):
    def load(self, donation_id: int) -> Donation: ...
    def save(self, donation: Donation) -> None: ...

Adapter

The piece that fits one outside system into the plug.

One adapter stores donations in Postgres. A second adapter keeps them in memory for tests. A new channel, such as a chat app, is a new adapter. The core does not change.

Where the three agree

Values do not change

Domain-driven design asked for it in 2003. Functional programming asks for it everywhere.

Eric Evans defined the value object as immutable in the book that named domain-driven design. A functional programmer reads that page and sees a rule they already follow.

Wrong states must be impossible

Each idea has a tool for it, and the tools do the same job.

Object-oriented code hides the constructor. Functional code lists each legal state as its own type. Domain-driven design calls the protected rule an invariant. All three stop a refunded pledge from existing.

The world stays at the edge

Three names for one structure.

Domain-driven design has repositories and translation layers. Object-oriented design has ports and adapters. Functional design has a pure core and a thin shell. Draw each one and you get the diagram at the top of this page.

An event is a fact

A fact cannot change, so an event is immutable data.

Apply the events in order and you get the current state. A functional programmer calls that a fold. A domain modeler calls it the history of the aggregate.

The code reads like the business

Types can list each state that can exist.

Donation = Pledged | Received | Refunded is one line of code. A fundraiser can read it and say if it is right.

Where they conflict, and how each conflict ends

Six conflicts. The first one is the real one. The others follow from it.

State that changes

The donation changes itself: donation.receive().

Nothing changes. A function returns a new value.

How it ends: the aggregate becomes a step from one state to the next. The function takes a state and a command and returns an event.

Where the behaviour lives

Methods live on the object.

Data and functions live apart.

How it ends: keep the functions in the same file as the type, with business names. Domain-driven design warns against rules that leak into service code. It does not care about the syntax.

Variants

A tree of classes. A new kind is easy to add.

A closed list of types. A new operation is easy to add.

How it ends: use the closed list inside the domain, where the states are known. Use interfaces at the edges, where new systems arrive.

Outside systems

Give the domain object a database to call.

The decision makes no calls.

How it ends: load, then decide, then save. A decision that needs more data in the middle is the hard case. Load that data before the decision.

Errors

Throw an exception.

Return the error as a value.

How it ends: a business rejection is a returned value. An exception is for a technical failure, such as a lost connection.

Storage tools

Most database mappers expect objects that change.

The domain values never change.

How it ends: the adapter translates between the two. This is extra code, and it is a real cost of the style.

The same rule, written two ways

The rule: a pledge becomes a received donation when the payment arrives.

One object does everything

class Donation:
    def receive(self, payment):
        if self.status != "pledged":
            raise Exception("Already received")
        self.status = "received"     # changes itself
        self.db.save(self)           # calls the database
        self.mailer.send_receipt()   # sends an email

To test the rule, you need a database and an email system, or copies of them.

A pure core and a thin shell

# core: decides, touches nothing
def receive(donation, payment):
    match donation:
        case Pledged(amount=a) if payment == a:
            return PaymentReceived(donation.id, payment)
        case Pledged():
            return Rejected("Payment does not match")
        case _:
            return Rejected("Only a pledge can be received")

# shell: all the outside calls
def handle_receive(donation_id, payment, store, bus):
    result = receive(store.load(donation_id), payment)
    if isinstance(result, PaymentReceived):
        store.save(Received.from_event(result))
        bus.publish(result)
    return result

To test the rule, you call receive with a pledge and an amount. The shell is short enough to read in one look.

What you get, and what you pay

Benefits

  • Tests need no database and no stand-in objects.
  • Each business rule is in one place, with a business name.
  • A new channel is a new adapter. The core does not change.
  • The same input gives the same output, so you can replay and audit.
  • Two tasks cannot damage shared data, because no data changes.

Costs

  • More types, and translation code between the domain and the database.
  • Friction with frameworks that expect objects that change.
  • A learning curve for developers trained on objects.
  • Too much ceremony for a form that saves a record.
  • The risk of theory for its own sake. Take the simple parts first.

When to choose it

Choose it when

  • The rules are real: pricing, eligibility, matching, a thing that moves through states.
  • A mistake costs money or trust.
  • Two or more channels use the same logic.
  • The system will live for years.

Do not choose it when

  • The work is a prototype that tests an idea.
  • The feature only stores and shows records.
  • The code is a script, glue or a screen.
  • One model holds the full system with no strain.

The low-cost version

Take three things: values that do not change, one pure function for each decision, and a thin shell. That is most of the benefit for a small part of the cost.

Do not add event storage as the only record without a named need. That decision is hard to reverse. The style works without it.

What changes when an AI agent writes the code

People who build with coding agents wrote about this in 2025 and 2026. Most of it is opinion from practice. Two studies measured something. Each line says which.

Where the writers agree

A shared vocabulary helps the agent

Without the business words, the agent guesses.

Martin Fowler and Unmesh Joshi say the conversation with the model builds the language of the domain. In their words: “Without it, the model has no concrete reference points and must guess at meaning.”

Opinion

Borders keep the agent's reading small

An agent reads a limited amount. A change must fit in that amount.

Several writers judge a design by one test: can the agent load everything one change needs? A bounded context and a plug at each edge both pass that test.

Opinion

Data that does not change lets the agent think about one function

The effects of a call are its inputs and its output, and nothing else.

John Davenport makes this argument for Elixir. In code that changes data, the agent must read each function a call touches. He also gives the limit: “a function can still be locally sensible and globally wrong.” His post shows no numbers.

Opinion

A type stops an agent. Advice does not

An agent works around a written rule. It cannot work around a compile error.

Justin Le works in Haskell and reports that agents switch off warnings and style checks to get code to pass. His fix is a hard block on switching them off.

Experience report

What agents do badly without controls

They fall back to simple record-keeping

The agent builds forms over tables, not a model with rules.

Vaughn Vernon wrote two of the standard books on domain-driven design. After ten months with a coding agent, he says of a generated domain model: “It's rarely better than unacceptable.” His cause: few good domain models are public, so the models learned from few.

Experience report

They avoid strict types

They add a check where a type was necessary.

Justin Le again, on types that make wrong states impossible: “AI will, by nature, NOT do this, even the latest frontier models.” He sees agents drop a planned type and put the error text into an existing text field.

Experience report

They improve the number, not the goal

One agent cut memory use when the goal was cost. It saved one dollar a month.

Miłosz Smółka of Three Dots Labs tells this story. He also warns that an agent can merge two things that look alike and are separate on purpose, such as a donation in fundraising and a donation in accounting.

One example

What was measured

Models choose borders badly

They do the word list well. They draw the borders and the aggregates badly.

Eisenreich, Jusic and Wagner led a model through five design steps. The authors conclude that a person must review the result.

Measured

Models make more errors in pure functional languages

Haskell and OCaml did worse than Scala, which mixes the two styles.

The same study found that models often write step-by-step code in functional syntax. This supports a mixed language with functional rules over a pure functional language.

Measured

Nobody has compared the styles directly

No study tests whether an agent succeeds more often in one style.

The claim that unchanging data gives fewer agent bugs is reasonable. It has no published data behind it.

A gap

Who owns the core

The writers split on this. Kevin Sookocheff keeps the core for a person and gives the shell to the agent.

Could I debug it at 2 a.m.?

Kevin Sookocheff's test for which code a person must understand in full.

Justin Le lets the agent write more, inside types and checks that it cannot switch off. Fowler and Joshi divide by time: a person finds the right abstraction, and the agent applies it after it is stable.

The three positions agree on one thing. The agent does not choose the model.

Check yourself

Five questions. Answer in your head, then open the line.

Which idea decides where a word changes meaning?

Domain-driven design. The border is a bounded context.

A function reads the clock to see if a pledge is late. Is it pure?

No. The clock is outside the function. The shell reads the clock and gives the time to the function as an input. Then the function is pure.

donation.refund() changes the status and sends an email. What moves to the shell?

The save and the email. The decision stays in the core and returns a DonationRefunded event.

A donor tries to refund a pledge. Is that an exception?

No. It is a business rejection, and the core returns it as a value. An exception is for a technical failure.

You build a contact form that saves one record. Do you use this style?

No. There is no rule to protect. Plain code is correct here.

Sources

Eric Evans, Domain-Driven Design (Addison-Wesley, 2003). Scott Wlaschin, Domain Modeling Made Functional (Pragmatic Bookshelf, 2018). Gary Bernhardt, the talk Boundaries (2012), for the functional core and the imperative shell.

Martin Fowler and Unmesh Joshi, Conversation: LLMs and Building Abstractions (2025), martinfowler.com/articles/convo-llm-abstractions.html.

Vaughn Vernon, This Is Your Agent on Domain-Driven Design (2026), wso2.com/library/conference/2026/05/this-is-your-agent-on-domain-driven-design.

Justin Le, LLMs Will Cheese Your Types (2026), blog.jle.im/entry/llms-and-haskell-1-constraint-evading-behavior.html.

Miłosz Smółka, Domain-Driven Design matters more when AI writes your code (2026), threedots.tech/post/ddd-and-ai-coding.

Kevin Sookocheff, Human Core, AI Shell (2026), sookocheff.com/post/ai/human-core-ai-shell.

John Davenport, Immutability Is Why LLMs Reason About Elixir Better (2026), codemyspec.com/blog/elixir-immutability-llm-code-generation.

Eisenreich, Jusic and Wagner, a study of language models in domain-driven design steps (2026), arxiv.org/abs/2603.26244.

Perish or Flourish? A Holistic Evaluation of Large Language Models for Code Generation in Functional Programming (2026), arxiv.org/abs/2601.02060.

Press Notes at the bottom right to mark up any block, or click any line to edit it directly. The diagram caption and the demo are drawn by the page, so they take a note and not an edit.

Back to the topic, or see all explorations.