473,320 Members | 1,825 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

interface and static (abstract base class?)

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
Nov 15 '05 #1
1 1872
phoenix <pa******@skynetWORK.be> wrote:

<snip>
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

33
by: Chris Capel | last post by:
What is the rationale behind the decision not to allow abstract static class members? It doesn't seem like it's a logically contradictory concept, or that the implementation would be difficult or...
2
by: Paul Selormey | last post by:
I have looked through the documents but could not find any information on this. Is anything like static properties in interfaces? If not, how do I define property in interface to be made static...
20
by: Ole Hanson | last post by:
I am accessing my database through an interface, to allow future substitution of the physical datastore - hence I would like to declare in my Interface that my DAL-objects implementing the...
6
by: Tamir Khason | last post by:
I have some classes that basicly do the same things but different way. There are no default constructors in those classes each constructor should recieve same value So Fooclass:MyBasicClass...
9
by: phl | last post by:
hi, I am kind of confused aobut interfaces and abstract classes. In short as I understand it, an interface is like a contract between the class and the interface, so that certain funtions must...
1
by: Joel | last post by:
Why does this work: using System; namespace ConsoleApplication1 { class Class1 { static void Main(string args)
12
by: craigkenisston | last post by:
Hi, I will use an example to do a simplified description of my problem, please don't laugh. I just "believe" I would have to use either interface or abstract classes, but I've not ever write an...
18
by: Bradley | last post by:
I'm trying to determine if there's a general rule for when an Interface should used vs. an Abstract Class. Is there any design advantage to using one or the other? Brad
4
by: Ray Dukes | last post by:
What I am looking to do is map the implementation of interface properties and functions to an inherited method of the base class. Please see below. ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.