When transitioning a model using Command.NextState -> commands.State, is it dangerous to share pointers or reference types between model states?
For example,
type State struct {
index map[string]string
}
func (writeFooBarCommand) NextState(s commands.State) commands.State {
current := s.(State)
next := current
next.index["foo"] = "bar"
return next
}
I believe that the existing model state and the new model state will share a reference to the underlying map, meaning manipulations via the old state instance or the new state instance will reflect in both objects. I currently make it a habit to deep copy my model states when transitioning, but my question is whether or not the deep copy is necessary.
When transitioning a model using
Command.NextState -> commands.State, is it dangerous to share pointers or reference types between model states?For example,
I believe that the existing model state and the new model state will share a reference to the underlying map, meaning manipulations via the old state instance or the new state instance will reflect in both objects. I currently make it a habit to deep copy my model states when transitioning, but my question is whether or not the deep copy is necessary.