I am trying to create a factory design pattern. Am I moving towards the correct direction? Object creation is not in a separate class that manages new objects when the type is passed in as a parameter.
class PetFactory
{
public: Pet* createPet(std::string type)
{
Pet * pet = null;
if (type == "Dog")
{
pet = new Dog();
}
else if (type == "Cat")
{
pet = new Cat();
}
else if (type == "Rabbit")
{
pet = new Rabbit();
}
else if (type == "Hamster")
{
pet = new Hamster();
}
return pet;
}
};
Aucun commentaire:
Enregistrer un commentaire