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

Yavaconf_-_How_to_make_your_architecture_scream_with_functional_domain_modeling.pdf

 Yavaconf_-_How_to_make_your_architecture_scream_with_functional_domain_modeling.pdf

Bartłomiej Słota

September 28, 2022
Tweet

More Decks by Bartłomiej Słota

Other Decks in Programming

Transcript

  1. The common way - the big ball of … (you

    name it) Primitive obsession
  2. The common way - the big ball of … (you

    name it) Business rules’ leakage
  3. The common way - the big ball of … (you

    name it) Cannonical model
  4. The common way - the big ball of … (you

    name it) Communicating failures with exceptions
  5. Questions •How much information do we get from looking at

    the code?
 •What is the di ff erence between stationId and customerId? Should they be equal when they have the same values?
 •Is Lending always a lending? Or maybe it can be just a reservation that is never used? Do I get this information from the Lending class?
 •Does Lending class tell me what can I do with the reservation?
 •Does Lending class tell me what does it mean that the lending was fi nished?
 •Is extending reservation for more than 5 minutes really an exceptional situation?
  6. What’s the function? String, String, Integer, Customer -> Lending VehicleId,

    StationId, ReservationDuration, Customer -> Lending
  7. Chaingin results MakeReservationCommand -> Lending Lending -> Session MakeReservationCommand ->

    Result<MakeReservationFailure, Lending> VS Lending -> Session
  8. Map

  9. A type that wraps another type That has a function

    wrapping the original value And has a function that unfolds the original value, applies some other function, and creates the new wrapped value of the same type
  10. Is it a bird? Is it a plane? Is it

    the twister? NO! It’s a monad!
  11. Meta model of the logic Stable logic Logic closure The

    choice of the closure - Stable process - Small susceptibility to change - Many variants - Many details - Dynamically de fi ned Impl1 Impl2 Impl3
  12. How to make your architecture scream? •Model your code thinking

    of functions and work fl ows instead of state •Have referential transparency in mind •Model your class hierarchies so that they correspond to the true domain and codomain of your business function •Avoid side e ff ects like exceptions and mutability •Keep your domain pure - move IO to the outside layer of your onion •Use monadic types to improve readability and robustness