chapter8 (state pattern)