Lesson 24. Capstone 4

 

It’s back to bank accounts again! This time you’re going to apply the lessons you learned on domain modeling into the bank account system. In this exercise, you’ll do the following:

  • Use options in practical situations
  • Use discriminated unions to accurately model a closed set of cases
  • Work with collections with more-complex data
  • Enforce business rules through the type system

24.1. Defining the problem

When you completed lesson 19, you had a version of a working bank account application that could handle persistence to disk and back again, as well as remove mutation for your command handler. Now you’re going to remove some of the “code smells” that have been left lying around by introducing some lovely F# domain modeling. You’ll have to do the following:

  • Replace the unbounded command handlers with a fixed discriminated union
  • Embed options enabling you to cater to situations where you “might not have any data” rather than the arbitrary default values you’ve used so far
  • Consider how you might enforce business rules via some F# types to stop overdrawn customers from withdrawing funds.

24.1.1. Solution overview

24.2. Stronger typing with discriminated unions

24.3. Applying Option types with the outside world

24.4. Implementing business rules with types

Summary