Design Patterns code in Java