Jump to content
  • Advertisement
Sign in to follow this  
Endar

Factory pattern

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!