Asuming I have this two classes:
public class Threshold {
int min;
int max;
public virtual int calculate(int min, int max)
{
//calculate basic Threshold
}
}
public class AdvancedThreshold : Threshold {
int min;
int max;
int extra;
public override int calculate(int min, int max, int extra)
{
//calculate Advanced Threshold
}
}
I cannot do this, because the base method has two parameters whereas the subclass method has three parameters.
What would be the best design practice to approach this problem? is it possible to use polymorphic objects? do I need to use composite objects instead of inheritance?
I've read something similar to my problem here https://stackoverflow.com/a/56904/3032175
But I don't really understand the solution. Thank you.
Not exactly sure what you're trying to achieve, but you might want to rethink the design. It seems that the min/max/extra
values should not be passed to the Calculate
method but set as properties or passed in a constructor.
public class Threshold
{
public int Min { get; set; }
public int Max { get; set; }
public virtual int Calculate( int input )
{
// logic goes here
}
}
public class AdvancedThreshold : Threshold
{
public int Extra { get; set; }
public override int Calculate( int input )
{
// advanced logic goes here
}
}