Implement Core GoF Patterns in Java and Discuss Trade-offs
Context
You are designing a small Java library and want to demonstrate three classic GoF design patterns with concise examples. You should:
-
Implement a thread-safe, lazy Singleton.
-
Implement the Factory Method pattern.
-
Implement the Strategy pattern and a simple client that uses it.
-
Compare these patterns in terms of trade-offs, extensibility, and testability.
-
Refactor one example to reduce coupling and enable dependency injection (constructor injection is fine).
Keep code snippets small and focused on illustrating the pattern rather than full application logic.