Design pattern for java