Satisfying Interface requirements

  • Thread starter Thread starter DavidGB
  • Start date Start date
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?
 
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
 
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
 
<Embarrased grin>
I added the 'Implements' clauses and answered my own questions

Sorry, Please ignore this thread!
David
 
Back
Top