Hi,
On Sat, 2006-09-09 at 00:58 +0200, Marcus Lindblom wrote:
> Allen Bierbaum wrote:
> > Why does OpenSG 2.0 introduce the singleton holder template? What is it
> > meant to solve?
> >
> > Assuming it is just meant to modularize the singleton pattern, why not
> > use derivation to do the same thing.
> >
> > Something like:
> >
> > class SceneFileHandler : public Singleton<SceneFileHandler>
> > {
> > ...
> > };
> >
> >
> > I assume there is a reason, I just wanted to know what it is so I can
> > understand it better. :)
>
> Not knowing anything really, I suspect the SingletonHolder is similar to
> Loki's in terms of what it offers (since it has the same name :). So
> they might have just used that one, which is nice and offers some good
> stuff for you when dealing with singletons. It does not use inheritance
> tough. (Could be in order to be non-intrusive, i.e. you don't have to
> modify the type you're making into a singleton.)
>
> A nice thing about not deriving is that you can put the template
> definition and instantiation in one translation unit (.cpp-file) only
> (effectively hiding it in a static the()-function), to avoid each client
> of the singleton class instancing the code.
>
> Actually, this is required if you have dynamically loaded libaries. A
> common problem with all of those is that you tend to get several copies
> of global data that's defined in the headers. (Since the
> os-runtime-linker doesn't resolve such things.) This is especially
> prominent in singletons. I ran in to that when we dll-ified our
> application (it was one big exe previously.)
>
> So.. there you have a pretty good reason, not to mention increased
> compile and link times by avoiding instantiation of the
> singleton-template-class everywhere.
the above was one reason, another is that if you put them into the
class hierarchy as Allen did the Singleton<T> class has to support
all functions where you are only allowed to call up exactly one level
in the inheritance hierarchy (e.g. constructors). And some of the
singletons inside OpenSG (factories) actually have a class hierarchy
where the inner constructors take arguments. So I did not want to change
this (which is obviously possible) and was looking for singleton
solution where I don't have to put in these call-through constructors.
regards,
gerrit
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users