Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A domain driven approach to Kotlin's new types

pakoito
September 22, 2016

A domain driven approach to Kotlin's new types

A short roundup of two new class types introduced in Kotlin, and how our programs can use them to improve maintainability.

Final code snippet: https://gist.github.com/pakoito/0b942c6f68441b76756a7a761cb9272d

Talk summary: https://skillsmatter.com/meetups/8409-lscc-talks-september-2016

pakoito

September 22, 2016
Tweet

More Decks by pakoito

Other Decks in Programming

Transcript

  1. DATA PROBLEMS ▸ Beans and not Beans ▸ Immutability ▸

    Nullables and validation ▸ equals(), hashCode(), and toString()
  2. DATA CLASSES IN KOTLIN ▸ Synthetic accessors ▸ val for

    immutable, var for mutable ▸ Nullable types and Default values ▸ data qualifier: all of the above plus equals(), hashCode() and toString()
  3. DOMAIN DRIVEN DESIGN WITH TYPES ▸ Separate data from behaviour

    ▸ Express execution flows as data ▸ Encode behaviour in types
  4. DOMAIN DRIVEN DESIGN WITH TYPES ▸ Separate data from behaviour

    ▸ Express execution flows as data ▸ Encode behaviour in types ▸ Make illegal states unrepresentable
  5. DOMAIN DRIVEN DESIGN WITH TYPES ▸ Separate data from behaviour

    ▸ Express execution flows as data ▸ Encode behaviour in types ▸ Make illegal states unrepresentable ▸ Push validation to edges
  6. SEALED CLASSES IN KOTLIN ▸ Closed inheritance ▸ Requires dereferencing

    using when() -> is ▸ Data classes and implement interfaces (1.1) ▸ Type alias (1.1)
  7. WHAT IF I CAN’T USE KOTLIN? JAVA 8 ▸ JavaSealedUnions

    JAVA 6 ▸ RxSealedUnions SCALA ▸ You should be on stage pacoworks.com/ @fe_hudl github.com/pakoito