I've been studying Spring State Machine and State design pattern since I have to develop a microservice with Spring Boot and persisted objects with a lot of confused states that need to be cleared up, and I am looking for a clean design solution out of that mess. I checked DDD, State concepts and State Machine seeing which ones to apply
I am not sure about how to implement some concepts, and how to connect them. I would like to understand if:
@Scope("prototype")
I got that: - DDD wants Domain Objects that have more functionality that simple Data Objects like in this quite complete but a little dated article on DDD - State pattern should encapsulate how the Context element should behave in that particular case - The State Machine is about encapsulating the management of the passage between one State and another - Should they work together, the State should not dictate which is the next State on a specific command, but generate an Event for the State machine and the State machine would choose (or block if there are Guards that fail) the new State - Somehow the new State would have to be set in the Context by the State Machine
Usually the Context object should delegate directly to the State object. But since the State machine dictates the change in the State of the object, should't in this case the Context delegate to a sort of Proxy State? Should be a/the State Machine be injected into the Entity or the Proxy?
Any thoughts, suggestions, even partial answers on some of these questions would be really appreciated.
BTW I just
DDD is all about protecting the business logic and make sure that it's not affected, or coupled, with infrastructure. When you look at an entity, you should directly understand what it's capable of and which part of the domain that it takes care of.
To me, state machines is not part of the domain. They are a facilitator and part of the application layer which controls what should happen in the domain. Then again, it's really hard to answer on an abstract level since DDD is all about modeling on a very "real" level.
If you could explain with a simple example what you are trying to accomplish it would also make it easier to write a more specific answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With