The applications I develop have to subscribe to various sources of data, I get new, update and removal messages and update data in heap accordingly. For each source, is creating a singleton like the following that holds and manages messages a bad idea? I find these singletons convenient (a bit verbose though, since i have to write INSTANCE everytime) to use and easy to unit test. What are the pros and cons of this approach?
public enum Trades {
INSTANCE
private final Map<String, Trade> = new ConcurrentHashMap<>();
public void add(Trade trade){}
public Trade get(String id) {}
}
Aucun commentaire:
Enregistrer un commentaire