113Composition Lens Part 1
Organic and Synthetic approaches
There are two main approaches to encoding a domain. We will re-
fer to them as “organic” and “synthetic”. In the organic approach,
you begin by coding the Order GUI with what you already have.
As you recognize regularities in the code, you begin to factor
those out into reusable parts. Those parts form a lower layer.
The synthetic approach is the complementary process. You
rst identify regularities in the domain, then encode those as
concepts in your model in the layer. Then you build the Order GUI
out of those. Both approaches have merit. Both have negatives.
The organic approach is good for exploring a domain where
the structure is not apparent to you. By diving in and coding, you
are able to make forward progress. And you oen see the struc-
ture later as you are coding. We commonly discover structure
due to repeating patterns. But we can also nd it by encountering
diculties. Things that are harder than they should be probably
mean you’ve got the structure wrong.
The synthetic approach doesn’t start with the code. It starts
with an analysis of the domain. You look for repeated patterns
and important structures. You develop an understanding of those,
then you encode it in your programming language. The synthetic
approach is good when the domain is well-understood (such as
accounting) and you have a way to explore it, such as access to an
expert (an accountant).
The synthetic approach is oen misunderstood. The carica-
ture of it is that a programmer, with little understanding of a do-
main, on their own begins dreaming up abstractions, then cod-
ing those. But this is not how it works. It takes disciplined study
and skilled analysis before coding happens.
The truth is that we code in both modes alternatively. Both do-
main analysis and exploratory coding are great sources of infor-
mation. This is why we model in code and seek rich feedback. We
might analyze the domain, encode what we discover, then nd
that there was something we missed, which we explore organi-
cally.