lundi 2 mars 2015

Is this a pattern? What would be its name?


I'm learning about patterns and would like to know if this implementation is one of them.


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, is this a pattern? What would be its name? Or is it an anti-pattern?





Aucun commentaire:

Enregistrer un commentaire