interface and static (abstract base class?)

  • Thread starter Thread starter phoenix
  • Start date Start date
P

phoenix

Hello,

I guess I'm missing to logic behind the limitation or I'm doing something
wrong (most likely). I have the following interface and class

public interface IRBSPParser
{
void Parser(byte [] b, int offset, int size)
}

public class RBSPType1 : IRBSPParser
{
public void Parser(byte [] b, int offset, int size)
{
// do whatever needed
}
}

No problem there but now I would want the function Parser declared static
and that just won't compile. static in the interface is an invalid item and
when I try to use static in the class it tells me the class doesn't
implement the interface. Why is this invalid in the first place? And how
could I change it? Should I create an abstract base class?

TIA

Yves
 
No problem there but now I would want the function Parser declared static
and that just won't compile. static in the interface is an invalid item and
when I try to use static in the class it tells me the class doesn't
implement the interface. Why is this invalid in the first place? And how
could I change it? Should I create an abstract base class?

Static methods aren't really inherited, and can't be overridden, so
"abstract static" (which is what it would be in an interface,
effectively) doesn't really work. Even if you could declare it, how
would you invoke it? You normally use an instance of the implementation
type, but refer to it through the interface - that's how .NET knows
which method you really mean to call. How would that work in a static
case, where you have no actual implementation "in your hand"?

There are certainly times when it would be useful to do so, and
fundamentally I don't think there's a reason beyond conceptual
simplicity why it shouldn't be the case, but it would require more
language syntax than is currently available, at least.
 
Back
Top