I have a class library for carrying out a series of calculations based on a given standard. That standard has now been revised and i need to update the code to carry out calculations according to the new standard, whilst also maintaining the previous standard. Whilst I'm tempted to copy the whole lot and change the bits that have changed in the later standard it seems to go against all good principals of code design. Currently i'm thinking that i should duplicate all classes for the later standard and inherit anything that hasnt changed. But Is there a smarter way...?
namespace standard_2010
{
class Calc1
{
double result {get;}
void calculate()
}
class Calc2
{
double result {get;}
void calculate()
}
class FinalResult
{
Calc1 m_c1;
Calc1 m_c2;
double result {get;}
FinalResult()
{
m_c1 = new standard_2010.Calc1()
m_c2 = new standard_2010.Calc2()
}
void calculate()
{
// Calculate the referenced calculations
m_c1.calculate();
m_c2.calculate();
// save the result of this calculation which is a function of the referenced calcs
this.result = f(m_c1.result, m_c2.result)
}
}
}
namespace standard_2020
{
class Calc1 : standard_2010.Calc1
{
double result {get;}
void calculate()
}
class Calc2 : standard_2010.Calc2
{
double result {get;}
void calculate()
}
class FinalResult : standard_2010.FinalResult
{
FinalResult()
{
m_c1 = new standard_2020.Calc1()
m_c2 = new standard_2020.Calc2()
}
}
}
Aucun commentaire:
Enregistrer un commentaire