lundi 6 avril 2015

An explanation of why this type of static cache pattern is an anti-pattern or bad?

Imagine you need a lookup cache for something.


I know this implementation is wrong. For one thing, you cannot mock it for unit tests.


But I know there must be other reasons it is bad.



public class FooCache {

private static Map<String, String> cache = new HashMap<>();

public static populate(...) {
...
}

public static String getWhositForWhatsit(String whatsit) {
return cache.get(whatsit);
}

Aucun commentaire:

Enregistrer un commentaire