View previous topic :: View next topic |
Author |
Message |
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Sat May 15, 2004 8:31 am Post subject: Factories |
|
|
A number of factory objects as well, and Steve and company use a fairly consistant interface for them all. So we've got three possible methods of handling these.
------------------------------
Option #1:
Settle on a standard Factory class layout, such as:
Code: |
// for any class Foo
class FooFactory
{
public:
Foo createFoo();
char[] getTypeName();
// any bits that are special to this class
// such as .getLanguage() for gpu programs
proteced:
private:
}
|
------------------------------
Option #2:
Pretty much the same as #1, but with a templated abstract Factory root class.
------------------------------
Option #3:
Factory methods on the object class.
------------------------------
I'm rather heavily in favor of #3. One of the reasons OGRE has factories, is so that one can use FooFactory.destroyFoo(...) to get rid of objects and guarantee cleanup gets done. I don't expect this to be an issue in Sinbad. So long as we define a good destructor where needed, and try to use delete and auto wherever appropriate, the cleanup should be taken care of.
Thoughts?
And what is it with me lately and listing options in threes... excuse my obsessive-compulsive moment. _________________ Chris Nicholson-Sauls |
|
Back to top |
|
|
andy
Joined: 15 Mar 2004 Posts: 71
|
Posted: Sat May 15, 2004 10:08 am Post subject: |
|
|
A separate factory class makes it simpler to return alternate implementations depending on the whims of the library. _________________ "Complacency is a far more dangerous attitude than outrage." - Naomi Littlebear |
|
Back to top |
|
|
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Sat May 15, 2004 11:09 am Post subject: |
|
|
I agree, but as far as I can see that never happens in OGRE. All of the Factories are for Overlay GUI Elements, Particle System Emitters/Affectors, and then the one for Zip Archives. The only ones that do anything more than new an instance and return it, are the Emitters/Affectors, whose create method invariably looks like this:
Code: |
ParticleEmitter* BoxEmitter::createEmitter(void)
{
ParticleEmitter* emit = new BoxEmitter();
mEmitters.push_back(emit);
return emit;
}
|
That's why I think we'd be just as well off without seperate classes for factories. The only other thing that varies, is that some factories do take parameters to the createXXX() method. For instance:
Code: |
HighLevelGpuProgram* CgProgramFactory::create(const String& name, GpuProgramType gptype)
{
return new CgProgram(name, gptype, sLanguageName, mCgContext);
}
|
_________________ Chris Nicholson-Sauls |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|