5 Modelling Domain Behaviors

 

This chapter covers

  • Modeling complex behaviors as pipelines
  • Letting data guide the design
  • Making illegal Behaviors impossible to represent

We’re going to leave the cozy and safe worlds of oil curing and checklists and jump head first into the messy, frantic world of software development. No more isolated modeling. We’re going to take the data-oriented tools we’ve learned and apply them to building a complete feature.

This means dealing with everything that makes software development hard. Databases, frameworks, services, and, worst of all, existing legacy decisions. Everything in this chapter will be done inside of an existing application (one we’ll make up as we go). We’re going to learn how to carve out a world built on data inside of an existing one built on mutation and identity objects.

This chapter will be challenging. The feature we’re going to implement is non-trivial and built from complex requirements. At the end of this, you’ll be battle hardened and have all the tools needed to tackle any feature in your own applications.

Let’s get started!

5.1 "Encouraging timely payments"

We're going to explore the spiritually fulfilling world of invoice processing and charging late fees. (Or, as it's known in corporate speak, "implementing systems which encourage timely payments.") Customers aren't paying their bills on time, and the accountants can't keep up, so we're going to automate their process.

5.1.1 Invoicing (briefly)

5.1.2 The Legacy System!

5.1.3 A bunch of prior decisions designed around “free"

5.2 Modeling domain behaviors around existing code

5.3 Modeling domain behaviors around data

5.3.1 Telling a story with data

5.3.2 Represent runtime decisions as compile time algebraic data types

5.4 Fleshing out the representation

5.4.1 Creating wrapper types and being OK with comingled Identities

5.4.2 Being OK with imperfect semantics

5.4.3 Designing the algebra for Late Fees

5.4.4 Modeling the decisions

5.4.5 The high-level data model

5.5 Fitting into the rest of the world

5.5.1 Fitting into what’s already there

5.5.2 Separate how you get the data from what you do with it

5.6 Decoupling from the Tyranny of What's Already There

5.7 The finished data model

5.8 Wrapping up

5.9 Summary