Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

State Machine implementation with Kotlin and SpringBoot

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been trying to implement a state machine with Kotlin as part of my SpringBoot application. I have essentially the following:

  • 1
  • a State class containing all the states



  • 2
  • a Trigger Class (action that triggers a change of state)




  • 3
  • a Transition class that essentially takes an initial state, action and final state



  • 4
  • and a TransitionConfiguration holding all allowed transitions



    I am struggling with writing the actual state machine class. Since it is part of my SpringBoot app and I need to be able to get hold of the entity/dto will be inside my service, however I am not sure how to go about. In particular, I am not sure how to write the method, which is what it should actually apply the state change. Can you help? Can you provide any indication of what that would look like?

    Thank you


     
    Saloon Keeper
    Posts: 12133
    258
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You can ignore Spring for most of this. If you want to store the machine's current state in a database, just write it on top of an interface that is responsible for storing and retrieving the current state and let Spring inject it.

    I don't really know Kotlin, but in Java I would write something like this:
     
    Always look on the bright side of life. At least this ad is really tiny:
    Thread Boost feature
    https://coderanch.com/t/674455/Thread-Boost-feature
      Bookmark Topic Watch Topic
    • New Topic