Singletons

I have an application that implemented its own Logging class which is a singleton.

I realize that OOD expects you to always use set and get methods but in this case - since there is only one - should I REALLY call the getInstance() function in every method I need it in or should I just declare a global Logger and reference that all the time? What would the good design practice be?

null

[407 byte] By [CSAngela] at [2007-11-26 21:29:41]
# 1
the point of the Singleton pattern is so that you do NOT use global variables, using one to refer to it would just defeat the purpose, don't you think?, besides, what is so bad to calling getInstance() versus calling someGlobalVar, both of them return the same thing.
Clem1986a at 2007-7-10 3:10:18 > top of Java-index,Java Essentials,New To Java...
# 2
Logging? You could do worse than taking a look at java.util.logging or log4j and see how they do it.
DrLaszloJamfa at 2007-7-10 3:10:18 > top of Java-index,Java Essentials,New To Java...
# 3

The logger actually instantiates a and configures a JUL. And it's not a very pretty implementation.

The first time it is called it must be called as

MyLogger logger = MyLogger.getInstance(properties).

But after that the usages is:

Logger logger = MyLogger.getInstance().getLogger().

Kinda messy and gross but I didn't write it.

I just find it a pain to have to "get" it in nearly EVERY method.

Thanks for the advice...I guess I'll stick to calling the getInstance method.

CSAngela at 2007-7-10 3:10:18 > top of Java-index,Java Essentials,New To Java...