Bug in sigleton classes in fairbase/base [message #9626] |
Tue, 27 October 2009 14:11 ![Go to next message Go to next message](/theme/gsi/images/down.png) |
Bertram Kopf
Messages: 110 Registered: March 2006
|
continuous participant |
From: *ep1.ruhr-uni-bochum.de
|
|
Hi,
in the "base" directory there is the attempt to provide a couple of singleton classes (e.g. FairRootManager, FairRun, FairRunSim, etc.). Due to the fact that the relevant constructors are defined as public, these singletons are not properly implemented. For those classes, it is possible to create more than only one object and this can therefore cause some troubles. For singletons, it is a must to define the constructors in the protected or private region.
Therefore I would like to ask the relevant developers to fix this bug as soon as possible.
Thanks in advance,
Bertram.
|
|
|
|
|
Re: Bug in sigleton classes in fairbase/base [message #9630 is a reply to message #9629] |
Tue, 27 October 2009 15:27 ![Go to previous message Go to previous message](/theme/gsi/images/up.png) |
Mohammad Al-Turany
Messages: 518 Registered: April 2004 Location: GSI, Germany
|
first-grade participant |
From: *gsi.de
|
|
Hi Bertram,
As I said before, it is nicer to have the ctor privet, but it is not a really a bug that change behavior of the singleton. in the compiled code you always use the instance and this is working, all these singleton classes are some kind of managers that have to be created from the macro (RunAna and RunSim) or by the framework itself (IO manager) and then the user uses the instance.
Quote: | But exactly this should be avoided in a singleton. The only way to get access to a singleton object should be possible via a static instance function. The singleton itself has to take care of calling its own ctor.
Therefore I would prefer to follow the recommendations of object oriented design patterns.
|
The design pattern book is simply some recommendations for implementations, and does not present the object oriented standard, even C++ itself is not 100% object oriented (and this make it usable in contrary to JAVA or smaltalk) . Anyway when I have time I will change it, but not now.
regards
Mohammad
|
|
|