Move Java class-centered designs toward Clojure data models, pure transformation functions, composition, explicit state, and adapters that keep object lifecycle concerns contained.
Java codebases often encode domain concepts as classes and behavior as methods. In Clojure, you typically model the same domain as plain data and behavior as functions that take and return those values.
This section covers practical refactors: extracting state from objects, replacing method calls with function calls, and choosing explicit boundaries for I/O. The focus is incremental change without breaking production behavior.
| OO design element | Clojure refactoring direction |
|---|---|
| Domain object with fields | Map, record, or validated data shape with explicit keys. |
| Method-heavy service | Namespace of functions that accepts data and dependencies explicitly. |
| Inheritance hierarchy | Composition, protocols, multimethods, or data-driven dispatch. |
| Hidden mutable collaborator | Explicit atom, database boundary, queue, or adapter-owned resource. |