Interfaces.vb
' 
'  Interface example by Josh Santomieri
'  Santomieri Systems - 08/25/2006
'

Imports Microsoft.VisualBasic
Imports System.Collections

''' 
''' Interface for custom lists.
''' 
Public Interface IMyList

	''' 
	''' Gets or sets the object at the index i.
	''' 
	Default Property Item(ByVal i As Integer) As Object

	''' 
	''' Gets the count of items in the list.
	''' 
	ReadOnly Property Count() As Integer

	''' 
	''' Allows you to add an object to the list.
	''' 
	''' The object to add to the list.
	Sub Add(ByVal item As Object)

End Interface

''' 
''' Represents a list.
''' 
Public Class MyList
	Implements IMyList

	Private _list As ArrayList

	''' 
	''' Creates a new MyList.
	''' 
	Public Sub New()
		Me._list = New ArrayList()
	End Sub

	''' 
	''' Adds an item to the list.
	''' 
	''' The item to add to the list.
	Public Sub Add(ByVal item As Object) Implements IMyList.Add
		Me._list.Add(item)
	End Sub

	''' 
	''' Gets the count of items in the list. (interface declaration)
	''' 
	Public ReadOnly Property Count() As Integer Implements IMyList.Count
		Get
			Return Me._list.Count
		End Get
	End Property

	''' 
	''' Gets or sets the object at index i. (interface declaration)
	''' 
	Default Public Property Item(ByVal i As Integer) As Object Implements IMyList.Item
		Get
			Return Me._list(i)
		End Get
		Set(ByVal value As Object)
			Me._list(i) = value
		End Set
	End Property
End Class

''' 
''' Represents a list #2.
''' 
Public Class MyList2
	Implements IMyList

	Private _list As ArrayList

	''' 
	''' Creates a new MyList.
	''' 
	Public Sub New()
		Me._list = New ArrayList()
	End Sub

	''' 
	''' Adds an item to the list.
	''' 
	''' The item to add to the list.
	Public Sub Add(ByVal item As Object) Implements IMyList.Add
		Me._list.Add(item)
	End Sub

	''' 
	''' Gets the count of items in the list. (interface declaration)
	''' 
	Public ReadOnly Property Count() As Integer Implements IMyList.Count
		Get
			Return Me._list.Count
		End Get
	End Property

	''' 
	''' Gets or sets the object at index i. (interface declaration)
	''' 
	Default Public Property Item(ByVal i As Integer) As Object Implements IMyList.Item
		Get
			Return Me._list(i)
		End Get
		Set(ByVal value As Object)
			Me._list(i) = value
		End Set
	End Property
End Class

''' 
''' Gets information about a list...
''' 
Public Class ListInfo

	''' 
	''' Gets the count of items in a list that uses the IMyList interface
	''' 
	''' A list of type IMyList.
	''' The number of items in the list.
	Public Shared Function ItemsInList(ByVal list As IMyList) As Integer
		If list Is Nothing Then
			Throw New ArgumentNullException("list")
		End If
		Return list.Count
	End Function

End Class

''' 
''' Represents the main entry point for the program.
''' 
Public Class MyProgram

	Public Shared Sub Main(ByVal args As String())

		Dim list As New MyList()
		Dim list2 As New MyList2()

		list.Add("test")
		list.Add("test1")

		list2.Add("testing")
		list2.Add("testing1")
		list2.Add("testing2")

		' Using one function, write out the number of items in the lists...
		' Output should be: 
		'    Items In MyList: 2
		'    Items In MyList2: 1
		Console.WriteLine("Items In MyList: " & ListInfo.ItemsInList(list))
		Console.WriteLine("Items In MyList2: " & ListInfo.ItemsInList(list2))
	End Sub
End Class