I have a class that basically represents model parameters and encapsulates the logic to calculate model values ββwith these parameters. I am trying to decide if this class should be immutable. In practice, model instances will be generated by fitting to a certain data set, so in this sense it makes sense (at least for me) that this instance be immutable, since it is tied to external data.
On the other hand, there will be a GUI to allow the user to do an βwhat-ifβ in which they can change parameters to see how they change the model values. Therefore, I could make the model volatile, to make it simple, or create new copies every time the parameter changes. The latter seems inconvenient, especially if, for example, there are 5 parameters that can be marked up and down individually ... it seems that I would have to implement the SetX () method for each parameter that returns a copy, right?
Am I overdoing it, or is there a correct template here? (This is C # code, although I think it is language independent)
source
share