Static Interfaces
Regards
Regards
what would you use them for?
I use interfaces when I want to abstract communication of callers and callees. So they can have their implementation details burried in their concrete classes but a caller can treat a range of callees the same based on the exposed interface.
I would not know how to use a static interface where all functions would be static and would have no "connection" to an associated object (missing this pointer). This could only be used on something like a singleton where also the state could be static.
Maybe you can be more convincing by giving a pattern where static interfaces would be of help?
Bye,
SvenC
what do you mean by static interfaces ?
if you mean to make all methods static in an interface , then this cannot be declared in C# on both the interface level and the method level .
so would you please be more clear about what do you mean by static interfaces ?
regards ,
Hussein Ahmad
http://HusseindotNET.BlogSpot.com
// Static interface
public static interface IFigureOptions
{
Color BackColor {get;}
Color ForeColor {get;}
Pen BorderPen {get;}
}
// Circle class
public class Circle : IFigureOptions
{
public static Color BackColor
{
return Color.Black;
}
...
}
// Ellipse class
public class Ellipse : IFigureOptions
{
public static Color BackColor
{
return Color.Red;
}
...
}
// Renderer
public class Renderer
{
void DrawCircle(IFigureStyle style)
{
...
}
}
Regards
I think there is a technical problem where to store the function pointer table of the interface functions. With static interfaces the type (Ellipse, Circle) itself would need such a function pointer table (for BackColor, ForeColor, BorderPen).
For current interfaces (which are not static) this information is stored with each object instance.
I read somewhere that interfaces are not implemented as vtables in .Net but I do expect that somewhere somehow there must be some information which override of a function in a class hierarchie is going to be called...
//non-static interface IFigureOptions figureOptions = new Circle(); figureOptions.BackColor = Color.Red; //static methodcalls Circle.BackColor = Color.Red; |