Java remake of codes in design pattern