Moderators: OGRE Team, Moderators
Singleton Classes rock. Simply think of it as a way of ensuring that the class you are calling is created only once. That means it can be called from anywhere ( by including header of course ) and you know that your calling the 1 static instance and not creating another instance. I use them mostly for my main application and then for every single "manager" class that I use. Here is an example of a Menu manager

Imperil wrote:Kristian you have to realize that singletons are not *always* bad (even though they were almost written off as an anti-pattern by the consortium), it depends on how they are used.
Imperil wrote:Factory classes are a prime example of where the singleton pattern shines.
Although when using classes that are singletons I would definately use a const ref rather than calling getSingleton() over and over (obviously I'm only talking about while in the scope).
Kristian wrote:Last time I checked with my gang of four "factory design pattern" was not on the same page as singleton design pattern
Isnt the optimizer taking care of that ? Check out the genereate asm it should just push the pointer into the ean and then jump to the the function address. since the method is static i think its the same as pushing a const. Im not totally sure about this though.
Kristian wrote:The gang of four also best knows as GOF is a group of 4 people who wrote a book with descriptions of the most common design patterns including singleton(/ simpletons) and factory<->product pattern.
In this book the factory pattern and singleton pattern are not related.
In other words factories have nothing to do with singletons, since they're 2 diffirent design patterns. A solution to a random problem on the other hand can happily fit into both patterns.
In this book the factory pattern and singleton pattern are not related.
Users browsing this forum: Yahoo [Bot] and 2 guests