Layers of Logic

The running program

The Registry

One program, built across the whole course. It starts as two variables in Phase II and ends up as something several threads can use at once. Every step below is a real exercise, and each one adds to the same program.

29 steps9 phases

Most courses give you a new toy problem every chapter, and you throw each one away. The Registry is here so that you don't. When you meet inheritance in Phase VII, you're not modelling animals that make noises. You're giving the Registry you already wrote a family of unit types, and you can see exactly what it bought you.

  1. Phase II. Data and Memory

    • 2.1The Registry Begins

      This exercise checks whether you can choose types on purpose instead of typing int everywhere.

    • 2.2The Money Bug

      This exercise checks whether you can recognise the situation where double is the wrong tool.

  2. Phase III. Logic and Flow

    • 3.1Registry Flags in One int

      This exercise checks whether you can use bitwise operators for what they are really for, which is packing many yes-or-no answers into one number.

    • 3.2Registry Status Rules

      This exercise checks whether you can turn a set of written rules into readable conditional code.

    • 3.3Registry Roll Call

      This exercise checks whether you can drive a loop from user input rather than a fixed count, and whether you pick the loop shape that fits.

  3. Phase IV. Data in Rows

    • 4.1The Registry Gets a Roster

      This exercise checks whether you can hold several parallel facts about many units using only arrays.

    • 4.2Build a Growable Array Model

      This exercise checks whether you can build the core strategy used by array-backed lists by separating size from capacity, allocate a larger backing array when full, and copy.

  4. Phase V. Methods

    • 5.1The Registry Grows Methods

      This exercise checks whether you can restructure a long main into named pieces, and whether you use overloading where it genuinely helps rather than everywhere you can.

  5. Phase VI. Objects

    • 6.1From Parallel Arrays to Objects

      This exercise checks whether you can see what a class buys you, by rewriting code you already wrote badly.

    • 6.2Chain Them Properly

      This exercise checks whether you can put validation in exactly one place.

    • 6.3Close Both Reference Leaks

      This exercise checks whether you can identify a mutable reference crossing a class boundary and apply defensive copying on both input and output.

    • 6.4A Registry That Counts Itself

      This exercise checks whether you can choose class-level or per-instance ownership for each member and predict class initialization separately from object construction.

  6. Phase VII. The Four Pillars

  7. Phase VIII. Identity and Contracts

    • 8.1Load the Registry From a File

      This exercise checks whether you can read structured data from a file, handle the bad rows, and close the file properly.

    • 8.2An Immutable Registry

      This exercise checks whether you can build a nested immutable structure, where a class holds other immutable objects.

    • 8.3Registry Identity

      This exercise checks whether you can decide what identity means for a real domain object rather than mechanically including every field.

    • 8.4Enums Carry Data

      This exercise checks whether you can move a rule out of scattered if statements and into the type it belongs to.

    • 8.5A Registry Built on Interfaces

      This exercise checks whether you can put the whole phase together.

  8. Phase IX. Text and Types

  9. Phase X. The Collections Framework

Phases XI to XIV don't have their steps yet. The Registry will get stream reports, loading that fails properly, a look at what it costs in memory, and finally two threads touching it at once.