Design patterns implementation examples

State

Definition:

Changes behavior of an object according to his inner state. After calling changing state operation object behaves differently. (After performing state changing operation)


Example:

An example is for instance girl/boy which before wedding acts differently than after… A wedding is an event which changes behavior – after wedding a friend turns out to be a completely different person. Another example may be behavior at a stressed/nervous person. If we ask him about something when he is nervous he will answer differently than he would answer if the would be relaxed or in a good humour. In other words the answer depends not only on the question but on the state a person is in at that time.


C++ code:

/src/state.cpp
Download source code

State UML class diagram:
State UML class diagram

State UML sequence diagram:
State UML sequence diagram