CSE Roadmap

Core tier · about 4 hours · 6 parts

Part 3 of 6 · 1 min read

Classes

A ledger and three split rules.

Class Job in one sentence
Ledger Holds members and net balances, records expenses and settlements, and simplifies
Split (interface) Turns a total and some detail into a share for each person (strategy)
Equal, Exact, Percent The three split rules

Everything else is plain data. The ledger needs no Expense object to compute balances, but keeping a list of expense records is wise for history and for undo. It is left out of the code below to keep the core small.

Why a strategy? A new split rule, such as "by number of nights stayed", is a new class. The ledger does not change. This is the open-closed idea of Level 3.

A rule returns shares that add up to the total. The ledger checks this again before it changes any balance, so a faulty rule cannot unbalance the books.

Check yourself: 1. Which pattern are the three split rules? 2. Why does the ledger re-check that shares add up? 3. What data would a history list need?