Lecture 8-State pattern Flashcards
1
Q
What is the intent of the state pattern?
A
To allow an object to alter its behaviour when its internal state changed.
2
Q
What are the pros of the state pattern?(3)
A
-SRP: organize the code related to particular states into separate classes.
-Open/Closed principle: introduce new states without changing existing state classes of the context.
-Eliminate bully state machine conditionals.
3
Q
What are the cons of the state pattern?
A
-If state machine has only a few state or rarely changes–> might be overkill