Sample code of state pattern