Satisfying Interface requirements

D

DavidGB

I have a base class (B), and another class that subclasses it (S).
S also 'Implements' an interface.
Most of the requirements of this interface are met by methods and properties
in B.
But .net complains that the interface requirements are NOT met, unless I
shadow them in S.

Is this expected behavior?
 
D

DavidGB

Base class:

Public MustInherit Class DALObject
Implements IDisposable

Public Readonly Property ID as Integer
....
....

first Sub-class:

Public Class Asset
Inherits DALObject

Public Sub Persist()
....
....

Interface Class:

Public Interface BLLObject
Sub Persist()
ReadOnly Property ID() As Integer
.....
....

The final Class, which .NET flags as in error:

Public Class BLLAsset
Inherits Asset
Implements BLLObject
....
....

..NET flags the 'Implements' clause as an error saying that I need to
implement both the ID property AND the Persist Sub.
I can only get around it by 'shadow'ing them in the BLLAsset class.

Why won't the interface be satisfied by the methods in the base classes?

TIA, David
 
E

eschneider

Hi, David

There are lots of ways you can do this, but VB requires explicit interface
implementation. Vb will not assume just because you have that signature it
is true to the contract.

Maybe try something like this:
Public Interface BLLObject

Sub Persist()

ReadOnly Property ID() As Integer

End Interface

Public MustInherit Class DALObject

Implements IDisposable

Implements BLLObject

Public MustOverride ReadOnly Property ID() As Integer Implements
BLLObject.ID

Public MustOverride Sub Persist() Implements BLLObject.Persist

End Class

Public Class Asset

Inherits DALObject

Public Overrides Sub Persist()

End Sub

Public Overrides ReadOnly Property ID() As Integer

Get

End Get

End Property

End Class

Public Class BLLAsset

Inherits Asset

End Class
 
D

DavidGB

<Embarrased grin>
I added the 'Implements' clauses and answered my own questions

Sorry, Please ignore this thread!
David
 

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