upfront I develop software for big data applications of which use is beyond my control (it ends up with a user), but I am not a trained software developer. So I apologize for any wrong terminology.
Now my question is: Is a class hierachy justified when implemented mainly/solely to aide static checking (checking at compile time)??
A single "array" class may contain a 1, 2 or 3 dimensional array of floats as a variable (depending how the object is invoked) and has a method "inversion". Of course only 2D squared arrays can be inverted and I have the option to throw an exemption at run time if the method is called and the actual variable is 1D, 3D or 2D rectangular.
I could also make a class hierarchy which contrast child classes 1D, 2D, 3D, and 2D further into rectangular and squared. Then, the inversion method would only be defined for 2D squared. If "inversion" is called by 1D the compiler can pick that up as the method is not defined.
The latter approach is obviously more complicated and involves more code but it is the one I have preferred so far. I have preferred it because when one puts all the little bits and pieces together to large executables this way provides a lot of help to get it right at compile time, not when the exec is in the "wild".
Now I was told by a trained programmer that class hierarchies should never be implemented for the sake of aiding static checking as it makes maintenance unnecessary complicated, thus he would use approach 1.
If you have experience in that field I would appreciate if you could share it.
Thanks a lot