Delving deeper into C# - Classes & Interfaces
public class LinearConverter : ScalingConverter,IConvert,IReversibleConverter
{
public LinearConverter()
{
}
public LinearConverter(double factor,double offset)
: base(factor)
{
m_offset = offset;
}
...
|
public class C {
static int a;
static C() {
a = 0;
}
}
|
public class C
{
public C()
{
a = new X(b);
}
private readonly X a;
private const int b = 5;
}
|
public interface IConvert
{
double convert(double val);
string formatFormula(string argument);
}
|
When you are implementing an interface you have 2 choices: 1) just override the method as you would any virtual function: in this case the method will be accessible whether you have reference to a class itself or to an interface: public virtual double convert(double val) 2) Use "Named override" like this double IConvert.convert(double val) In this case the method will be visible only through a reference to an interface. This solves an important design problem from C++ where you needed to make you interface implementation methods always public which sometimes muddled the class interface making it too rich.