problem with interface implementation

Can I

Member
Joined
Oct 23, 2006
Messages
12
Location
Coventry, UK
Programming Experience
3-5
hello,

I'm using Visual Web Developer and am just beginning with VB.NET. I've came accross a strange problem - I have DAO inteface and want to implement it:
VB.NET:
Imports model
Imports Microsoft.VisualBasic

Namespace dao

    Public Interface BookDAO

        Function findAllBooks() As ArrayList
        Function findById(ByVal id As Integer) As Book

    End Interface

End Namespace

and

VB.NET:
Imports model
Imports Microsoft.VisualBasic

Namespace dao

    Public Class AccessBookDAO
        Implements BookDAO

        Private books As New ArrayList

        Private Shared instance As AccessBookDAO

        Private Sub New()
            Dim book1 As New Book
            book1.description = "book1 desc"
            book1.id = 1
            book1.price = 3.5
            book1.publisherId = 1
            book1.title = "book 1"
            book1.year = 2006

            books.Add(book1)
        End Sub

        Public Shared Function getInstance() As AccessBookDAO
            
            If instance Is Nothing Then
                instance = New AccessBookDAO()
            End If

            Return instance

        End Function

        Public Function findAllBooks() As ArrayList
            Return books
        End Function

        Public Function findById(ByVal id As Integer) As Book
            Dim result As Book

            For Each book As Book In books
                If book.id = id Then
                    result = book
                    Exit For
                End If
            Next

            Return result
        End Function

    End Class

End Namespace

but the IDE tells:
Error 2 Class 'AccessBookDAO' must implement 'Function findAllBooks() As System.Collections.ArrayList' for interface 'BookDAO'. C:\Documents and Settings\Can I\Pulpit\asp.net\sdfna\App_Code\dao\AccessBookDAO.vb 7 20 C:\...\sdfna\

Error 3 Class 'AccessBookDAO' must implement 'Function findById(id As Integer) As model.Book' for interface 'BookDAO'. C:\Documents and Settings\Can I\Pulpit\asp.net\sdfna\App_Code\dao\AccessBookDAO.vb 7 20 C:\...\sdfna\

for me the code looks correct, but I'm probably making some stupid mistake, as I've never been writing in VB before
 
If you write "Implements BookDAO" and press Enter key the interface members skeleton is auto-inserted into the class. Now that you have already written that just place the cursor immediately behind the impl...DAO line and press Enter key.
 
Well, yes, I could have told you had to add statements to the different methods specifying 'Implements BookDAO.method' but it is a good tip to have the IDE automatically write all that required code for you. :)
 
true, true ;)
I'm used to eclipse IDE and I hope I can find some of its funcionality in MS Visual series
 
Back
Top