I have a class called transform
, and its child classes, translation
, rotation
and scaling
, which are supposed to apply transformations on a triangle.
Each of the child classes overrides the apply_transform()
method:
class transform
{
protected:
virtual triangle apply_transform(const triangle&) const = 0;
public:
static triangle apply_transforms(const triangle&, const std::initializer_list<const transform*>&);
};
class scaling : public transform
{
...
public:
triangle apply_transform(const triangle&) const override;
};
//same for rotation and translation
I also have a function called apply_transforms
, which should be accessible to the outside world, and I use it to apply multiple transformations. I pass it a list of transform*
to enable polymorphism.
The only issue I have is that now, the child classes are also aware of this method. This is bothering me since a child class shouldn't be able to apply all of the other transformations.
Is there an elegant solution to this?
Make apply_transforms
a non-member function that is not included into header files required by classes implementing transform
.