//change to a new state public void ChangeState(TState <T> pNewState) { //keep a record of the previous state m_pPreviousState = m_pCurrentState; m_pNewState = pNewState; //for current state exit use //call the exit method of the existing state if (null != m_pCurrentState) { m_pCurrentState.Exit(m_pOwner); } //change state to the new state m_pCurrentState = pNewState; //call the entry method of the new state m_pCurrentState.Enter(m_pOwner); }