Baran Topal

Baran Topal


May 2024
M T W T F S S
« Feb    
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories


singleton use cases

baranbaran

Very briefly a singleton is something you can only have one of.

An example – think of a class that wraps writing to a log file.  You could pass an object around from class to class or you could have a singleton which you just use.

Another example, say, you are implementing a cache object which can be used by other classes. In this case, you may like to implement singleton object over cache class so that instances of other classes will use the same instance of cache. Sharing single database connection could also be a good use case.