AlessandroGnoatto / mafinlib

0 stars 0 forks source link

Maybe ConcurrentHashMap or Static Initialization is an alternative. #2

Open cfries opened 7 years ago

cfries commented 7 years ago

I am not sure if this class is truly useful - see my PM - but as a general comment you could use a ConcurrentHashMap here: https://github.com/AlessandroGnoatto/mafinlib/blob/f45726047d589c93a603a8a879dd2a3bbff6f846/mafinlib/src/org/mafinlib/patterns/Singleton.java#L47

Instead of using a Singleton that maintains a Map to other Singletons you may consider a static initialiser: https://stackoverflow.com/questions/3635396/pattern-for-lazy-thread-safe-singleton-instantiation-in-java

AlessandroGnoatto commented 7 years ago

I think I will use the Singleton implementation in each class separately once I have fixed it een though this is not very elegant. I wanted to have the pattern as a separate "template" and this was the initial idea of this class. I will deprecate the whole file.

cfries commented 7 years ago

With respect to Singletons I would also recommend the various answers here: https://stackoverflow.com/questions/137975/what-is-so-bad-about-singletons

Extensive use of Singletons is suspicious... :-)