This article begins with a series of posts that is a topic very timely and useful. The vastness of the sea in which we are about to sail would need many, many pages of this book I decided to break up into several parts to the discussion.
The use of state machines seems to me important in the planning system, especially when it comes to services.
What happens when we meet the state machine Go? But let
"dall'incomincio" here is an example of a simple state machine (and a bit 'useless) but does understand what are these mysteries.
<-routineQuit // blocks until quit is written to
This concept is very useful when programming object. As we saw in the previous article, the language has Go items. We create our object then around to the internal state which for convenience will contain only the index of the state in which we live.
type InternalState
myState struct {int;}
If we take that as a model in the picture above the internal state InternalState must be initialized, then go in the state 1 and then before finishing second in the state.
then compose in this way the function that will initialize our state machine:
func (state InternalState *) Init (inputValue int) {
state.myState = inputValue;} We will then need two functions for each state, a performing entry and exit:
func (* been InternalState) Stato1_Entry () {
}
func (* been InternalState) Stato1_Exit () { }
func (* been InternalState) Stato2_Entry () {
}
func (* been InternalState) Stato2_Exit () {
}
In the next post we will see how to combine all the components instead just created to pass the object's state from the initial to the final passing through intermediate states.
I also hope to have put some flea in his ear to examine a very interesting topic.