Skip to content

Code for a lighting talk based on Scott Wlashin's domain modelling principles.

Notifications You must be signed in to change notification settings

seankearon/illegal-states

Repository files navigation

Illegal States

Code for a lightning talk on making illegal states unrepresentable in C# and F#.

The code follows Scott Wlashin's excellent Designing with types blog series.

There are tests for each language, but these don't assert that the code is correct, they just show the shape of the data in the console:

img.png

How to follow

Start at the main branch, then follow the branches by number.

Main

This is the starting point. It shows a naive implementation of a contact type and how that's not safe.

public record Contact
{
    public string FirstName     { get; init; } = "";
    public string MiddleInitial { get; init; } = "";
    public string LastName      { get; init; } = "";

    public string EmailAddress  { get; init; } = "";
    public bool IsEmailVerified { get; init; }
    
    public string Address1 { get;      init; } = "";
    public string Address2 { get;      init; } = "";
    public string City     { get;      init; } = "";
    public string State    { get;      init; } = "";
    public string Zip      { get;      init; } = "";
    public bool IsAddressValid { get; init; }
}

Links

Bonus Ball

Scott Wlashin's series is really about domain modelling. The last section of the series presents a more meaningful challenge:

“A contact must have at least one of the following: an email, a postal address, a home phone, or a work phone”_

https://fsharpforfunandprofit.com/posts/designing-with-types-discovering-the-domain/

His book is excellent too!

https://fsharpforfunandprofit.com/books/

About

Code for a lighting talk based on Scott Wlashin's domain modelling principles.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published