Your comments

Is that the design pattern in which you use a conditional in a Factory class to create a specific concrete class?

I struggle with the same thing, but I think the key is to write to interfaces and not to implementations. I'm not sure what programming language you're using, but in Python it would something like this:

from abc import ABC, abstractmethod

class AppInterface(ABC):
    def __init__(self, state: 'StateInterface') -> None:
        self._state: StateInterface = state

class StateInterface:
    def __init__(self, app: AppInterface) -> None:
         self._app = app

Then, you can use your implementation to work with these interfaces:

class MyApp(AppInterface):
    ...

class FirstState(StateInterface):
    ...

class SecondState(StateInterface):
    ...

class ThirdState(StateInterface):
    ...

if __name__ == '__main__':
    third_state = ThirdState()
    second_state = SecondState()
    second_state.set_next(second_state)
    first_state = FirstState()
    first_state.set_next(second_state)
    app = MyApp(state=first_state)

Does this help you?