For those who don’t know about this sort of thing. It’s basically 3D vector relationships I am messing about with here…
I am making a little project to make useful electromagnetism calculations but I am not sure how to design it to prepare for future uses and other applications too.
Eventually I will have some graph outputs and make a gui of it but at the moment I just want it to be a terminal based program.
At the moment I am thinking to have a class called
RadialForm
which is for identities and nothing will be in component form in that Class. I will then have another class called
ComponentForm
which will do all computations for transforming coordinates with the main methods being
setRectangular(i j k)
setCylindrical(i j k)
setSpherical(i j k)
computeCurl(i j k) //not sure if these last two should be in another class so I gave them arguments
computeDiv(i j k)
Then later, I am going to want to be able to use Gauss’ Stokes and Greens theories on the RadialFrom and the ComponentForm classes, so I am thinking this should be another class too. I have an idea that there should be some sort of inheritance structure going on but I am not really confident deciding what goes where.
Also, both of the classes will be manipulated with a ‘divergence’ operator to get the curl and results from identities and do lots of other important stuff.
Key word here is decomposition: don’t try to put everything to just one (or in your case – just 2) classes, put every separate piece of functionality to separate class. This means that you need distinct classes for vectors (points) and probably for every algorithm. To make your design more reusable, consider introducing interfaces for similar tasks (say, for algorithms).
OOP is also strong in modeling of domain area objects and their relations. So try to lie down all objects from the domain you may need. Note, however, that sometime (in scientific programs especially) you may need additional classes just manipulate existing. Here your
ComponentFormis good example.Concerning inheritance, general rule is: if you are not sure, don’t use it. Interfaces or delegation (depending on your needs) is better option in most cases.