Headfirst design pattern study and sample code