Baran Topal

Baran Topal


April 2024
M T W T F S S
« Feb    
1234567
891011121314
15161718192021
22232425262728
2930  

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.