6 Implementing the Domain Model
This chapter covers
- Implementing the domain model
- Functions and methods
- Designing around determinism
It's time to start writing some code! This chapter picks up where we left off in Chapter 5. We’ve finished modeling a complex invoicing domain that charges late fees. All of the data and behaviors have been sketched out. Now it’s up to us to implement them.
This requires care. A bad implementation can undermine a good data model. Methods in Java are up to no good most of the time. We’re going to learn how to get them under control.
We’re also going to spend time figuring out where to put all of this implementation code. So far, our modeling has been purposefully indifferent to details like class ownership. We focused only on the data and how it flowed through the program. But now we need to make architectural choices. Who should own these behaviors? Who can they talk to? Who can talk to them?
We’re going to learn how a really simple idea can transform both how we implement our methods and how we organize them into classes.
6.1 On the criteria by which we break down an implementation
In the last chapter, we tweaked the design of our methods with a simple heuristic: separating how we get the data from what we do with it.