I have many models in my project, and some other classes just need the class declaration and pointer type aliasing. It does not need to know the class definition, so I don't want to include the model header file. I extract all the model's declaration into one file to let every classes reference one file.
model_forward.h
class Cat;
typedef std::shared_ptr<Cat> CatPointerType;
typedef std::shared_ptr<const Cat> CatConstPointerType;
class Dog;
typedef std::shared_ptr<Dog> DogPointerType;
typedef std::shared_ptr<const Dog> DogConstPointerType;
class Fish;
typedef std::shared_ptr<Fish> FishPointerType;
typedef std::shared_ptr<const Fish> FishConstPointerType;
enum CatType{RED_CAT, YELLOW_CAT, GREEN_CAT, PURPLE_CAT}
enum DogType{HATE_CAT_DOG, HUSKY, GOLDEN_RETRIEVER}
enum FishType{SHARK, OCTOPUS, SALMON}
Is it acceptable practice? Should I make every unit, which needs a class declaration, depends on one file? Does it cause high coupling?
Or I should put these pointer type aliasing and enum definition inside the class back?
cat.h
class Cat
{
typedef std::shared_ptr<Cat> PointerType;
typedef std::shared_ptr<const Cat> ConstPointerType;
enum Type{RED_CAT, YELLOW_CAT, GREEN_CAT, PURPLE_CAT}
...
};
dog.h
class Dog
{
typedef std::shared_ptr<Dog> PointerType;
typedef std::shared_ptr<const Dog> ConstPointerType;
enum Type{HATE_CAT_DOG, HUSKY, GOLDEN_RETRIEVER}
...
}
fish.h
class Fish
{ ... };
Any suggestion will be helpful.