Inheritance Question

S

steve

Greetings,

I have a question about interfaces and inheritance. We are going to
create X number of classes that are going to doSomething (see below) cool
with typed datarows. I optimistically (stupidly) created an interface class
(iFoo) for all the usual reasons. I then though each implementation of iFoo
could use a typed DataRow because typed DataRows inherit from DataRow.
There is no IDataRow. It has been awhile but I could have sworn a design
like this would have worked in C++. Am I way off, missing something simple
or drinking too early? Thanks in advance.........

Will not compile. Error is that Foo does not implement
doSomething(DataRow).
interface iFoo
{
void doSomething(DataRow)
}

class Foo : iFoo
{
void doSomething(TypedDataRow)
{
// do something really cool here
}
}
 
C

cody

Will not compile. Error is that Foo does not implement
doSomething(DataRow).
interface iFoo
{
void doSomething(DataRow)
}

class Foo : iFoo
{
void doSomething(TypedDataRow)
{
// do something really cool here
}
}


You must make every implemented method of an interface public and
non-static.
Besides, you should start class/interface/method names with an Uppercase
character.
 
S

steve

The code provided was pseudo code to illustrate a point and not intended to
be compiled. I understand that interface members must be public -
actually - there is no other choice. The C# complier errors on any method
modifier. Any thoughts on the real issue of TypedDataRow vs. DataRow?



cody said:
Will not compile. Error is that Foo does not implement
doSomething(DataRow).
interface iFoo
{
void doSomething(DataRow)
}

class Foo : iFoo
{
void doSomething(TypedDataRow)
{
// do something really cool here
}
}


You must make every implemented method of an interface public and
non-static.
Besides, you should start class/interface/method names with an Uppercase
character.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
 
C

cody

The code provided was pseudo code to illustrate a point and not intended
to
be compiled. I understand that interface members must be public -
actually - there is no other choice. The C# complier errors on any method
modifier. Any thoughts on the real issue of TypedDataRow vs. DataRow?


Now I understand your problem. A method that implements a method of a
interface
must have exact the same arguments as the prototyp specified in the
interface.
Even if TypedDataRow inherits from DataRow - it modifies the signature of
your method which is not allowed.

The only things that are allowed when implementing interface methods are
IIRC:

-add virtual modifier
-add abstract modifier
-add unsafe modifier
-add extern modifier
-add new modifier
-add sealed modifier
-add custom attributes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top