static-factory

How to choose between methods of acquiring dependencies?

I've seen at least three ways of acquiring dependencies in a Java object without coupling the object to the creation of the dependency; Dependency Injection - some framework injects a required object into another object based on an external configuration, example: Spring managed beans Dependency Lookup - a class looks up a required dep...

What is the best way to cache and reuse immutable singleton objects in Java?

Hi, I have a class representing a set of values that will be used as a key in maps. This class is immutable and I want to make it a singleton for every distinct set of values, using the static factory pattern. The goal is to prevent identical objects from being created many (100+) times and to optimize the equals method. I am looking ...