On Apr 18, 2:10 am, James Kanze <james.ka...@gmail.comwrote:
Quote:
Do you ever actually need both 3 and 4 in the same program?
>
But a resurected singleton isn't the same instance as the
original singleton. If you resurected, it's not really a
singleton anymore.
>
Note that your code may cause multiple creations during program
start-up as well. All it guarantees is that there is never more
than one instance of a singleton alive at any given time. Which
is fine if the singleton has no variable state, but if it has no
variable state, one can argue that there's no need for it to be
a singleton in the first place.
Well, the the singleton in this program is actually behaving as a
proxy for a remote object outside the program (and eventually might be
even across a network), which does have a variable state. The purpose
of this singleton is to open the remote connection, provide the remote
interface, and cleanly close the connection when it is done. So in
fact I don't mind a few extra open/close pairs during static/global
init or during static/global cleanup - because this is only for the
brief periods of program startup and shutdown (I don't like it, but
can live with it if I am still satisfying my constraints).
I care more that:
1) No messages to the remote server are lost (at least the code on
this end does everything it can to ensure this), such as another
static/global object that needs to utilize the remote log service
during its destructor to record important diagnostic info.
2) The connection is cleanly closed so there won't be issues trying to
reconnect if the client (this module) restarts suddenly. I can't
touch the server code, and it likes the client to disconnect before
allowing it to connect again.
Maybe I'm approaching the whole problem a bit wrong, it just seemed to
me the singleton was the closest to what I needed but it ended up
needed much more tweaking than I expected.
Thanks,
I do very much appreciate your feedback