/*!
@file
@author Albert Semenov
@date 06/2009
@module
*/
#ifndef __MYGUI_GENERIC_FACTORY_H__
#define __MYGUI_GENERIC_FACTORY_H__
#include "MyGUI_Prerequest.h"
#include "MyGUI_Types.h"
#include "MyGUI_Delegate.h"
namespace MyGUI
{
template <typename Type>
class GenericFactory
{
public:
typedef delegates::CDelegate1<IObject*&> Delegate;
static typename Delegate::IDelegate* getFactory()
{
return newDelegate(createFromFactory);
}
private:
static void createFromFactory(IObject*& _instance)
{
_instance = new Type();
}
};
}
#endif // __MYGUI_GENERIC_FACTORY_H__
本文介绍了一个通用工厂模式的模板实现,该模式可以用于创建特定类型的对象实例。通过使用委托(Delegate),此工厂模式能灵活地扩展和管理不同类型的对象创建过程。
1629

被折叠的 条评论
为什么被折叠?



