Slide 1

Slide 1 text

A Kotlin DSL for finite state machines Corneil du Plessis Chief Architect, JumpCO

Slide 2

Slide 2 text

About me

Slide 3

Slide 3 text

Quotable quotes K.I.S.S. – Keep it simple stupid! Graeme Mitchell “Everything should be a simple as possible, but no simpler” Albert Einstein

Slide 4

Slide 4 text

What is a state machine?

Slide 5

Slide 5 text

Examples – Packet Reader

Slide 6

Slide 6 text

Examples – Quotation Manager

Slide 7

Slide 7 text

A brief history of state machines ● FSM/FSA (Finite state machines / automa) ● DFA/NFA/NDFA (Non-deterministic state machine / automa) ● State tables / charts / maps ● Mealy / Moore machines (State + Input) vs (State) ● UML state machines ● SDL state machines

Slide 8

Slide 8 text

UML State Diagram

Slide 9

Slide 9 text

Finite State Machines - Turnstile

Slide 10

Slide 10 text

Finite State Machines – Double Lock

Slide 11

Slide 11 text

Finite State Machines – Secure Turnstile

Slide 12

Slide 12 text

State Event Next State Action LOCKED COIN UNLOCKED unlock PASS alarm UNLOCKED COIN return-coin PASS LOCKED lock Transition table for Turnstile

Slide 13

Slide 13 text

FSM Patterns ● Generate code from State Map - SMC Class per State, method per Event OR Huge switch statement ● Executable XML – SCXML ● Language Builder – Spring Statemachine

Slide 14

Slide 14 text

SCXML - Turnstile

Slide 15

Slide 15 text

SMC - Turnstile

Slide 16

Slide 16 text

FSM Features ● States ● Transition on Events ● Guard Expressions ● Entry / Exit Actions ● Typed Event Parameter ● Typed Return value ● Automatic transitions ● Timeouts ● Named State Maps ● Push / Pop transitions ● Multiplatform ● No 3rd party dependencies ● Visualisations plugin

Slide 17

Slide 17 text

KFSM DSL for Turnstile

Slide 18

Slide 18 text

Visualisation – Asciidoc – State Map

Slide 19

Slide 19 text

Visualisation – PlantUML – State Diagram

Slide 20

Slide 20 text

Useless Box – State diagram

Slide 21

Slide 21 text

AI Assistive technology for improved UX

Slide 22

Slide 22 text

Typical design pattern for FSM

Slide 23

Slide 23 text

An example – Choose a technology ● Kotlin/JS in the Browser Kotlin Only ● Kotlin/JS in the Browser JavaScript calling Kotlin ● Kotlin JVM in Spring Boot with WebMVC ● Kotlin JVM in Spring Boot with REST / HATEOAS (Sample Angular Client) ● Kotlin JVM on Android

Slide 24

Slide 24 text

That’s a wrap. Questions?

Slide 25

Slide 25 text

Resources ● Twitter - @corneil ● Slides - https://speakerdeck.com/corneil/kfsm-a-kotlin-dsl-for- finite-state-machines ● Project Source - https://github.com/open-jumpco/kfsm ● Samples - https://github.com/open-jumpco/kfsm-samples ● SMC - http://smc.sourceforge.net/ ● Spring Statemachine - https://projects.spring.io/spring- statemachine/ Questions?