I have two Java classes. The first one is called "Index", and the second one, temporarily, I called it "IndexCache":
public class IndexCache {
private static Map<String, Index> map = null;
static {
map = new HashMap<String, Index>();
}
@Override
public Index getIndexString(key) {
Index index = map.get(key);
if (index == null) {
index = new Index("yadayadayada");
map.put(key, index);
}
return index;
}
}
As you can see, IndexCache keeps a map of the Index objects to avoid to create the same object once and again.
Well, what programming technique is this? What would be its name?