Java code for Design Pattern