Since my previous question got closed because it was opinion-based, let me copy paste and add additional information for my use case.
This is more of a design question rather than a programming one.
I have a class that represents something. Suppose this class has certain member variables and functions.
Now, suppose I need some of these functions but others I need to reimplement because they need different mathematical formulas to be computed. Also assume that I need different variables.
Should I specialize the class and reimplement the common functions? Or is there another approach I am unaware of? Inheritance is clearly not an option, because I do not need the same variables. I thought about specializing the single functions too, but the issue is again that I need different variables.
How do I decide? Also: do I really need to reimplement all common functionalities, or is there something I can do to avoid this?
EDIT: Since this was considered an opinion-based question, here's my case. I am implementing a mathematical representation of a vector. Currently, the draft is done and it contains all functions that I need.
Now, I would like to make sure that this vector can be represented in different coordinate systems. For example, one vector might be in cartesian coordinates, another in polar coordinates, another in another coordinate system.
The current vector implementation allows multiple dimensions and types. For the cartesian-system vector, I would only need 2D vectors and two single coordinates. For a polar vector, I would again need 2D vectors but with different coordinate types (For example a cartesian vector has two points as variables; a polar vector has a point and an angle).
This means that I then need to reimplement certain functions. Consider, for example, that the cartesian vector dot product formula differs from that of a polar vector dot product.
Having a common base class would be indeed ideal, but I'm not sure if there is some common functionality between all of the different vectors which might be based on different coordinate systems.
Some code to let you understand my question follows. A normal vector looks something like:
template<typename T, std::size_t Size>
class Vector {
private:
T _vector[Size]{};
public:
// all the functions here
A polar vector, on the other hand, might look something like:
template<typename T>
class Vector {
private:
T coord;
T angle;
public:
// Some functions differ from the original vector,
// Some other functions have the same implementation.
... And so on. Note that for spherical vectors, I'd again have different data members, but some common functions. The same applies for other coordinate systems.