Creating the Dynamic Factory class

So far, we have only created our builders, which are equivalent to the classic Factory method pattern. However, we haven't seen the Factory part of the Dynamic Factory. Let's look at how the Mach5 Engine implements the StageFactory class:

class M5StageFactory { public: ~M5StageFactory(void); void     AddBuilder(M5StageTypes name, M5StageBuilder* builder); void     RemoveBuilder(M5StageTypes type); void     ClearBuilders(void); M5Stage* Build(M5StageTypes name); private:   typedef std::unordered_map<M5StageTypes,     M5StageBuilder*> BuilderMap;   typedef BuilderMap::iterator MapItor;    BuilderMap m_builderMap; }; 

As you can see, M5StageFactory isn't a very complicated class. Once you understand the design behind the patterns, ...

Get Game Development Patterns and Best Practices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.