I am creating a class which has an instance variable that has many different implementations, but the problem is that all of the implementations have a slightly different interface.
Example:
class GameObject {
virtual Transform * getTransform() = 0;
};
class Transform {
virtual void setPosition() = 0;
virtual Model getModel() = 0;
virtual void refreshModel() = 0;
virtual void Draw() = 0;
};
// This Class has a .cpp
class TransformImpl : public Transform {
virtual void setPosition();
Model getModel();
void refreshModel();
void Draw();
};
// This Class has a .cpp
class InstancedTransformImpl : public Transform {
void setPosition(int instance);
std::vector<Model> getModels(); // notice the difference in the interface
void refreshModel();
void Draw();
};
The point I want to make is that I only want one GameObject class thus I want my geTransform() method have a return type of class Transform. The problem I'm having is that since TransformImpl and InstancedTrasformImpl have slightly different interfaces I can't have getTransform() to return a Transform and instead I need to implement GameObject twice with lots of duplicated code.
Is there a good solution to implement GameObject once?
Or would it be better to have multiple GameObject implementations each having there respective TransformImpl's with a more lenient interface?
std::vector<Model> getModels()for both interfaces?Model getModel()coiuld be represented as a vector with one element.classcontains many instances of transform and the otherclasscontains only one instance. I'll updateModelandstd::vector<Model>a template parameter in interface/implementatoin ?setPosition()?