views:

80

answers:

3

Hi

Small design question here. I'm trying to develop a calculation app in C#. I have a class, let's call it InputRecord, which holds 100s of fields (multi dimensional arrays) This InputRecordclass will be used in a number of CalculationEngines. Each CalculcationEngine can make changes to a number of fields in the InputRecord. These changes are steps needed for it's calculation.

Now I don't want the local changes made to the InputRecord to be used in other CalculcationEngine's classes.

The first solution that comes to mind is using a struct: these are value types. However I'd like to use inheritance: each CalculationEngine needs a few fields only relevant to that engine: it's has it's own InputRecord, based on BaseInputRecord.

Can anyone point me to a design that will help me accomplish this?

+1  A: 

You can declare a Clone() method on your BaseInputRecord, then pass a copy to each CalculationEngine.

Seb
Clone seems like a good idea, you will have the original records intact and other calculation engines will have seperate copies.
Aseem Gautam
I have considered cloning but the amount of fields keep me from using this strategy
edosoft
+2  A: 

If you really have a lot of data, using structs or common cloning techniques may not be very space-efficient (e.g. it would use much memory).

Sounds like a design where you need to have a "master store" and a "diff store", just analogous to a RDBMS you have data files and transactions.

Basically, you need to keep a list of the changes performed per calculation engine, and use the master values for items which aren't affected by any changes.

Lucero
Interesting. I'll think about this
edosoft
+2  A: 

The elegant solution would be to not change the inputrecord. That would allow sharing (and parallel processing).

If that is not an option you will have to Clone the data. Give each derived class a constructor that takes the base Input as a parameter.

Henk Holterman