Suppose we have an abstract Element class from which the Triangle and Quadrilateral classes are Quadrilateral .
Suppose these classes are used in conjunction with interpolation methods that depend on the shape of an element. So, basically we create an abstract class InterpolationElement , from which we derive InterpolationTriangle and InterpolationQuadrilateral .
Then, to include the interpolation functionality in the Triangle and Quadrilateral , we add a const-reference data element in the Element class of type InterpolationElement , that is:
class Element { public: Element(const InterpolationElement& interp); const InterpolationElement& getInterpolation() const; private: const InterpolationElement& interpolation; };
Then we create a method (as described by Scott Meyers, Effective C ++) that initializes the local static object of the InterpolationTriangle class as
const InterpolationTriangle& getInterpolationTriangle() { static InterpolationTriangle interpolationTriangle; return interpolationTriangle; }
Thus, the Triangle class can be constructed as follows:
class Triangle : public Element { public: Triangle() : Element( getInterpolationTriangle() ) {} };
Here is my question: is this approach correct for including interpolation methods in my Element class? Is it used in professional scenarios?
I could directly implement all the interpolation methods of the Element class (as pure virtual) and override them in the derived Triangle and Quadrilateral . However, this approach seems cumbersome to me, since every time I need to improve or implement new interpolation functions, I would have to do this on these classes. Moreover, classes are becoming more and more (many methods) using this approach.
I would like to hear from you some tips and comments
Thanks in advance.
Additional Information:
class InterpolationElement { public: InterpolationElement(); virtual double interpolationMethod1(...) = 0; : virtual double interpolationMethodN(...) = 0; } class InterpolationTriangle : public InterpolationElement { public: InterpolationTriangle () {} virtual double interpolationMethod1(...) {