어떠한 객체를 생성할 것인지를 자식 클래스 마다 다르게 하여, 클래스마다 다른 객체를 갖도록 하는 것을
팩토리 메소드 패턴이라고 합니다.
class ItemOption
{
//각종멤버
};
class ItemOptionHeal : public ItemOption
{
//체력회복기능
};
class ItemOptionPoison : public ItemOption
{
//독기능
};
class ItemDurationType
{
//각종멤버
};
class ItemDurationTypeCount : public ItemDurationType //갯수제
{
//갯수제처리
};
class ItemDurationTypeTime : public ItemDurationType //시간제
{
//시간제처리
};
class Item
{
virtual ItemOption * CreateItemOption(){return new ItemOption;}
virtual ItemDurationType * CreateItemDurationType(){return new ItemDurationType;}
};
class EquipItem : public Item //장착아이템
{
virtual ItemDurationType * CreateItemDurationType(){return new ItemDurationTypeTime;}
};
class InstanceItem : public Item //갯수제사용아이템
{
virtual ItemDurationType * CreateItemDurationType(){return new ItemDurationTypeCount;}
};
class ItemHealingPotion : public EquipItem
{
virtual ItemOption * CreateItemOption(){return new ItemOptionHeal;}
};
class ItemPoisonDagger : public InstanceItem
{
virtual ItemOption * CreateItemOption(){return new ItemOptionPoison;}
};