Factory pattern

This topic is 4590 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I just read an article on the factory pattern.
Factory fact;

fact.Register<TRIANGLE>("triangle");
fact.Register<SQUARE>("square");

fact.create(TRIANGLE);
fact.create(SQUARE);


etc, etc, and so forth. Now, here's my question. I see in a lot of diagrams and people's code that they have a single abstract Factory class and then they have several TextureFactory, MeshFactory, etc. So, if you have to register a class before you duplicate it, why bother having many different factory classes? Why not just have a large one and register all the classes necessary with the big factory. Since I don't get it, I assume that I have missed something. I invite you to teach me something :D Edit: Hmmm, possibly this post should be in the Software Eng forum.

Share on other sites
This factory requires that all objects inherit from the same base class. This is not always a problem but that's the reason i use different factories in some cases.

When you use this factory,you need also to cast the object that are created by the factory. when using a different factory for each object this is not needed