chapter eight

8 Business Rules as Data

 

This chapter covers

  • Modeling business rules as data
  • Interpreters and DSLs
  • Not over thinking it and just writing code

Java gets unfairly associated with the architectural patterns that were popular in the age when it rose to prominence. It gets made fun of for its cathedrals of inheritance and needless abstractions. For many devs, there wasn’t a problem that couldn’t be “solved” by adding another design pattern.

Java has evolved, yet the perceptions around how we should build, and what it costs to do so, linger in the community’s unconsciousness. Modern Java is lean and confident. Records and pattern matching have changed how we approach design. New patterns are available to us. Leveraging them starts with data.

8.1 Let’s start with an example

At MegaCorp, large customer accounts have dedicated sales teams. These teams help customers navigate complex contracts, issue special discounts, and so on. Their commission is tied to the type of accounts they manage and the value of the deals they cut, so which account ends up under which team is steeped in historical decision, shifting org charts, and petty in-fighting. There’re no clean rules like “everything in the USA is handled by the US based sales team.” If only! Instead, it’s based on arbitrary and ever-changing rules.

8.1.1 What does it mean to be correct?

8.2 Muscling through the rule implementation

8.3 Capturing rules as plain data

8.4 Building a simple Algebra

8.4.1 Building better interfaces into the algebra

8.5 Variation I: Deciding what data means

8.6 Variation II: A more powerful interpreter for the same data

8.7 Variation III: Adding Type Safety

8.8 What did this cost us?

8.9 But It doesn’t do everything!

8.10 Data is flexible in a way that code isn’t

8.11 Extending the algebra:

8.12 Wrapping up

8.13 Summary