Hal9000,
I agree with you, I find the documentation a little hard to read at
times, but, the information is there. You may have to go back and read,
re-read and read again to get a solid understanding.
The general idea of an interface (as I understand them) is:
They provide a common group of functions and methods to which you must
follow. However, they do not contain any code that does any of the work.
For example, I created a new class called MyFriends; MyFriends "Implements"
or better put, makes available a predefined group of methods/functions of
IEnumerable. These methods/functions are defined in the Interface; so,
again, an interface simply defines the methods/functions that an object
which "Implements" it WILL contain.
The two statements you pointed out don't make sense at first, but, they make
perfect sense when you understand what an interface does.
1

interfaces do not provide implementation. - No they provide the empty
methods to which you, the developer will provide the logic. Interfaces only
tell you what you MUST at a minimum include.
2

Although interface implementations can evolve - Yes, you can add to an
"Implementation" of the interface to expose additional functionallity, but,
you cannot change the interface itself. If you did, that object that are
currently implementing the interface will no longer work, they may not have
the same signature, or functions that were once included.
Hope this helps,
Jared
For this example I used a WebForm, but, you can place it in a winodws or
console app just the same just change the Response.Write to
Console.WriteLine.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim Friends As New MyFriends
'Create a new friends class and fill it with some of your Northwinds
friends
With Friends
.AddFriend("Nancy", "Davolio")
.AddFriend("Andrew", "Fuller")
.AddFriend("Janet", "Leverling")
.AddFriend("Margaret", "Peacock")
.AddFriend("Steven", "Buchanan")
End With
'Create a new instance of an IEnumerator, which is another interface, it
exposes three methods that MUST be implemented by
'The object that I will assign to it.
'Friends.GetEnumerator returns a new FriendEnumerator class that
implements the IEnumerator interface
Dim MyEnumerator As IEnumerator = Friends.GetEnumerator
'Loop through all the items in Friends
While MyEnumerator.MoveNext
'Notice that every time .Current or .MoveNext is called it returns
to the IEnumerator interface to retreive the results.
Dim Person As MyFriend = CType(MyEnumerator.Current, MyFriend)
Response.Write(Person.FirstName & " " & Person.LastName & "<br>")
End While
End Sub
'Place the rest of the code outside the main class definition
Public Class MyFriend
Private mFirstName, mLastName As String
Public Property FirstName() As String
Get
Return Me.mFirstName
End Get
Set(ByVal Value As String)
Me.mFirstName = Value
End Set
End Property
Public Property LastName() As String
Get
Return Me.mLastName
End Get
Set(ByVal Value As String)
Me.mLastName = Value
End Set
End Property
End Class
Public Class MyFriends
Implements IEnumerable
Private m_friends As New ArrayList
Public Sub New()
End Sub
Public Sub AddFriend(ByVal FirstName As String, ByVal LastName As
String)
Dim f As New MyFriend
f.FirstName = FirstName
f.LastName = LastName
Me.m_friends.Add(f)
End Sub
Public Function GetEnumerator() As System.Collections.IEnumerator
Implements System.Collections.IEnumerable.GetEnumerator
Return New FriendEnumerator(m_friends)
End Function
Private Class FriendEnumerator
Implements IEnumerator
Private m_friends As ArrayList
Private m_position As Int32 = -1
Public Sub New(ByVal Friends As ArrayList)
m_friends = Friends
End Sub
' Implementation of IEnumerator
Public ReadOnly Property Current() As Object _
Implements System.Collections.IEnumerator.Current
Get
Return m_friends(m_position)
End Get
End Property
' Implementation of IEnumerator
Public Function MoveNext() As Boolean _
Implements System.Collections.IEnumerator.MoveNext
m_position += 1
If m_position >= m_friends.Count Then
Return False
Else
Return True
End If
End Function
' Implementation of IEnumerator
Public Sub Reset() _
Implements System.Collections.IEnumerator.Reset
m_position = -1
End Sub
End Class
End Class
As far as the statements you mentioned "interfaces do not provide
implementation."