Reputation: 37
I have an old code base with 2 Entity classes (suppose with 10 measure). Old Functionality work like whenever u upload a Excel file it gonna parse the file and map to these entity class. Now as per new requirements Every year I am getting more measure added to these entity classes and getting new Excel file with 5 measure. How can I add versioning based on every year or how can I do mapping to the entity class every year from only one base Entity Class. Or how can I introduce this functionality without changing the design
Example of entity class-
[DataColumnAttribute]
public StatusLkup Insurance { get; set; }
[DataColumnAttribute]
public Code Status { get; set; }
[DataColumnAttribute]
public string test1 { get; set; }
Example of Excel file
Row 1 - Insurance, states, test1 Row 2 - 5, Co, test
Next year suppose 2 more new measure added to an entity class
[DataColumnAttribute]
public StatusLkup Insurance { get; set; }
[DataColumnAttribute]
public Code Status { get; set; }
[DataColumnAttribute]
public string test1 { get; set; }
[DataColumnAttribute]
public string test2 { get; set; }
[DataColumnAttribute]
public string test3 { get; set; }
Next year excel file
Row 1 - test1, test2 Row 2 - 12, 11
Upvotes: 1
Views: 257
Reputation: 31646
Since each year is a different, but based on the previous, one can create Interfaces
which will define (version) the years.
One can create interfaces regardless of the differences, but the point being, it versions the data.
By doing that you will version the data and be able to use/sort it accordingly with no changes in current code, just adding new code each year.
Example
Two interfaces and the second one inheirits from the first:
public interface IYear1
{
int Test1 { get; set;}
}
public interface IYear2 : IYear1
{
int Test2 { get; set;}
}
Then the classes derived:
public class Year1 : IYear1
{
public int Test1 { get; set;}
}
public class Year2 : Year1, IYear2
{
public int Test2 { get; set; }
}
Then in code we can create/determine what year is being processed:
var year = new Year2() { Test1 = 1, Test2 = 2};
if (year is IYear2)
Console.WriteLine("Year 2 Found");
if (year is IYear1)
Console.WriteLine("Year 1 Found");
The result is we identified two versions that are being used:
Year 2 Found
Year 1 Found
Upvotes: 2