Interface + derived method (via Overloads) problem

L

Lothar Behrens

Hi,

I have created a base class implementing an interface and a derived
class also implementing
the same interface. While figuring out that I am unable to call the
derived method of an instance
or the derived class I have added the keyword Overloads to the
function.

But this does not help. Why do I get these troubles ?

Thanks, Lothar

I have the following code:

Public Interface IDoSomething
Sub DoSomething()
End Interface

Public Class Adresse
Inherits MyBaseDLL.MyBaseClass
Implements MyInterfaces.IDoSomething

Public Sub DoSomething() Implements
MyInterfaces.IDoSomething.DoSomething
' Do log something
End Sub

End Class

Public Class KontaktAdresse
Inherits Adresse
Implements MyInterfaces.IDoSomething

Public Overloads Sub DoSomething()
MyBase.DoSomething()
' Do log something
End Sub

End Class
 
A

Armin Zingler

Lothar Behrens said:
Hi,

I have created a base class implementing an interface and a derived
class also implementing
the same interface.

That's not necessary because the base class already implements the
interface. An object that is an instance of the derived class automatically
fulfils this contract because the base class already does.

What's your intention? You can change it like this:

Public Interface IDoSomething
Sub DoSomething()
End Interface

Public Class Adresse
'Inherits MyBaseClass
Implements IDoSomething

Public Overridable Sub DoSomething() _
Implements IDoSomething.DoSomething
End Sub

End Class

Public Class KontaktAdresse
Inherits Adresse

Public Overrides Sub DoSomething()
MyBase.DoSomething()
End Sub

End Class

While figuring out that I am unable to call the
derived method of an instance
or the derived class I have added the keyword Overloads to the
function.

But this does not help. Why do I get these troubles ?

Thanks, Lothar

I have the following code:

Public Interface IDoSomething
Sub DoSomething()
End Interface

Public Class Adresse
Inherits MyBaseDLL.MyBaseClass
Implements MyInterfaces.IDoSomething

Public Sub DoSomething() Implements
MyInterfaces.IDoSomething.DoSomething
' Do log something
End Sub

End Class

Public Class KontaktAdresse
Inherits Adresse
Implements MyInterfaces.IDoSomething

Public Overloads Sub DoSomething()
MyBase.DoSomething()
' Do log something
End Sub

End Class



Armin
 
M

Mattias Sjögren

But this does not help. Why do I get these troubles ?

Why do you implement the same interface again in the derived class?
Can't you make DoSomething in Adresse an Overridable method and simply
override it in KontaktAdresse?


Mattias
 
L

Lothar Behrens

That's not necessary because the base class already implements the
interface. An object that is an instance of the derived class automatically
fulfils this contract because the base class already does.

What's your intention? You can change it like this:

   Public Interface IDoSomething
     Sub DoSomething()
  End Interface

  Public Class Adresse
     'Inherits MyBaseClass
     Implements IDoSomething

     Public Overridable Sub DoSomething() _
        Implements IDoSomething.DoSomething
     End Sub

  End Class

  Public Class KontaktAdresse
     Inherits Adresse

     Public Overrides Sub DoSomething()
        MyBase.DoSomething()
     End Sub

  End Class
















Armin- Zitierten Text ausblenden -

- Zitierten Text anzeigen -

I have done your suggestions. But I still have the same problem.

I have seen, when I step into such a function, that the function is on
the callstack. So it seems, that I cannot debug this
library.

I'll check that as next :)

Lothar
 
P

Phill W.

Lothar said:
I have created a base class implementing an interface and a derived
class also implementing
the same interface.

As far as I know, you can't do that; Visual Basic won't compile this.
While figuring out that I am unable to call the derived method
of an instance or the derived class ...

What makes you think so?
... I have added the keyword Overloads to the function.

For derived classes, you /really/ need to get Overrides working.
Public Class Adresse
Inherits MyBaseDLL.MyBaseClass
Implements MyInterfaces.IDoSomething

Public Sub DoSomething() Implements
MyInterfaces.IDoSomething.DoSomething
' Do log something
End Sub

End Class

Public Class KontaktAdresse
Inherits Adresse
Implements MyInterfaces.IDoSomething

This last line shouldn't compile.
Public Overloads Sub DoSomething()
MyBase.DoSomething()
End Sub

If you want to replace (or "extend") the base class' implementation, use
Overrides:

Public Overrides Sub DoSomething()
MyBase.DoSomething()
' do something else
End Sub

HTH,
Phill W.
 

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