Design pattern code explanation