I have a problem where I have a main class which solves a numerical problem. For simplicity, assume that it solves Ax=b
. Now, I want the user the ability to choose the method to solve it. There are thousands of options and each option has thousands of options within it.
My idea was to design it as follows: create a main class and then create subclasses for each method and subsubclasses for the details of each methods (which might interact via inheritance).
For instance, I envisage the user to do something like-
Model.method='CG'
Model.preconditioning=off
and then Model.Solve
and in the Model
class, there is a CG
subclass which runs. Within CG
there are methods CG_Precond
and CG_NoPrecond
which run depending on the preconditioning being on or off. (Assume that the methods are wildly different). So, in essence, the user is running Model.CG.CG_NoPrecond
.
Is this good design? Should nested classes be avoided?
One important note is that other than the Model
class, all of the subclasses contain only methods and no data of their own (other than what is returned).
I spent some time reading some really beautiful answers on SO and my problem ( I believe) aligns with the requirements of the accepted answer of Why/when should you use nested classes in .net? Or shouldn't you?.