I have this:

Public Class clsItem
Implements IComparer

Public Name As String

Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer
Implements IComparer.Compare
Dim empx As clsItem = DirectCast(x, clsItem)
Dim empy As clsItem = DirectCast(y, clsItem)

Return String.Compare(empx.Name, empy.Name)
End Function
End Class

<Serializable()> Public Class clsCategory
Inherits clsItem

Public SubOf As String
End Class

Public Class CategoryCollection
Inherits CollectionBase

Default Public ReadOnly Property Item(ByVal index As Integer) As
clsCategory
Get
Return CType(List(index), clsCategory)
End Get
End Property

Public Function Add(ByVal item As clsCategory) As Integer
Return List.Add(item)
End Function

Public Sub Insert(ByVal index As Integer, ByVal item As clsCategory)
List.Insert(index, item)
End Sub

Public Sub Remove(ByVal item As clsCategory)
List.Remove(item)
End Sub

Public Function IndexOf(ByVal item As clsCategory) As Integer
Return List.IndexOf(item)
End Function

Public Sub Sort()
InnerList.Sort(Me)
End Sub
End Class

<Serializable()> Public Class clsFile
Inherits clsItem

Public Category As String
Public FileName As String
Public Description As String
End Class

Public Class FileCollection
Inherits CollectionBase

Default Public ReadOnly Property Item(ByVal index As Integer) As clsFile
Get
Return CType(List(index), clsFile)
End Get
End Property

Public Function Add(ByVal item As clsFile) As Integer
Return List.Add(item)
End Function

Public Sub Insert(ByVal index As Integer, ByVal item As clsFile)
List.Insert(index, item)
End Sub

Public Sub Remove(ByVal item As clsFile)
List.Remove(item)
End Sub

Public Function IndexOf(ByVal item As clsFile) As Integer
Return List.IndexOf(item)
End Function

Public Sub Sort()
InnerList.Sort(Me)
End Sub
End Class

Now isn't there some way that I can create just an ItemCollection instead of
having to create a CategoryCollection, a FileCollection, and so on for every
new class I create?

--
Alex C. Barberi
Chief Executive Officer
VisionForce
http://www.visionforceweb.com

Re: Advanced OOP Question by cody

cody
Wed Feb 22 10:58:25 CST 2006

have a look into generics which come with VS2005.

"Alex C. Barberi" <AlexCBarberi@discussions.microsoft.com> schrieb im
Newsbeitrag news:A7E54BC4-904E-492E-B52A-14B571B4CAC5@microsoft.com...
>I have this:
>
> Public Class clsItem
> Implements IComparer
>
> Public Name As String
>
> Public Function Compare(ByVal x As Object, ByVal y As Object) As
> Integer
> Implements IComparer.Compare
> Dim empx As clsItem = DirectCast(x, clsItem)
> Dim empy As clsItem = DirectCast(y, clsItem)
>
> Return String.Compare(empx.Name, empy.Name)
> End Function
> End Class
>
> <Serializable()> Public Class clsCategory
> Inherits clsItem
>
> Public SubOf As String
> End Class
>
> Public Class CategoryCollection
> Inherits CollectionBase
>
> Default Public ReadOnly Property Item(ByVal index As Integer) As
> clsCategory
> Get
> Return CType(List(index), clsCategory)
> End Get
> End Property
>
> Public Function Add(ByVal item As clsCategory) As Integer
> Return List.Add(item)
> End Function
>
> Public Sub Insert(ByVal index As Integer, ByVal item As clsCategory)
> List.Insert(index, item)
> End Sub
>
> Public Sub Remove(ByVal item As clsCategory)
> List.Remove(item)
> End Sub
>
> Public Function IndexOf(ByVal item As clsCategory) As Integer
> Return List.IndexOf(item)
> End Function
>
> Public Sub Sort()
> InnerList.Sort(Me)
> End Sub
> End Class
>
> <Serializable()> Public Class clsFile
> Inherits clsItem
>
> Public Category As String
> Public FileName As String
> Public Description As String
> End Class
>
> Public Class FileCollection
> Inherits CollectionBase
>
> Default Public ReadOnly Property Item(ByVal index As Integer) As
> clsFile
> Get
> Return CType(List(index), clsFile)
> End Get
> End Property
>
> Public Function Add(ByVal item As clsFile) As Integer
> Return List.Add(item)
> End Function
>
> Public Sub Insert(ByVal index As Integer, ByVal item As clsFile)
> List.Insert(index, item)
> End Sub
>
> Public Sub Remove(ByVal item As clsFile)
> List.Remove(item)
> End Sub
>
> Public Function IndexOf(ByVal item As clsFile) As Integer
> Return List.IndexOf(item)
> End Function
>
> Public Sub Sort()
> InnerList.Sort(Me)
> End Sub
> End Class
>
> Now isn't there some way that I can create just an ItemCollection instead
> of
> having to create a CategoryCollection, a FileCollection, and so on for
> every
> new class I create?
>
> --
> Alex C. Barberi
> Chief Executive Officer
> VisionForce
> http://www.visionforceweb.com
>



Re: Advanced OOP Question by AlexCBarberi

AlexCBarberi
Wed Feb 22 11:26:28 CST 2006

No good. I'm using VS2002.

--
Alex C. Barberi
Chief Executive Officer
VisionForce
http://www.visionforceweb.com



"cody" wrote:

> have a look into generics which come with VS2005.
>
> "Alex C. Barberi" <AlexCBarberi@discussions.microsoft.com> schrieb im
> Newsbeitrag news:A7E54BC4-904E-492E-B52A-14B571B4CAC5@microsoft.com...
> >I have this:
> >
> > Public Class clsItem
> > Implements IComparer
> >
> > Public Name As String
> >
> > Public Function Compare(ByVal x As Object, ByVal y As Object) As
> > Integer
> > Implements IComparer.Compare
> > Dim empx As clsItem = DirectCast(x, clsItem)
> > Dim empy As clsItem = DirectCast(y, clsItem)
> >
> > Return String.Compare(empx.Name, empy.Name)
> > End Function
> > End Class
> >
> > <Serializable()> Public Class clsCategory
> > Inherits clsItem
> >
> > Public SubOf As String
> > End Class
> >
> > Public Class CategoryCollection
> > Inherits CollectionBase
> >
> > Default Public ReadOnly Property Item(ByVal index As Integer) As
> > clsCategory
> > Get
> > Return CType(List(index), clsCategory)
> > End Get
> > End Property
> >
> > Public Function Add(ByVal item As clsCategory) As Integer
> > Return List.Add(item)
> > End Function
> >
> > Public Sub Insert(ByVal index As Integer, ByVal item As clsCategory)
> > List.Insert(index, item)
> > End Sub
> >
> > Public Sub Remove(ByVal item As clsCategory)
> > List.Remove(item)
> > End Sub
> >
> > Public Function IndexOf(ByVal item As clsCategory) As Integer
> > Return List.IndexOf(item)
> > End Function
> >
> > Public Sub Sort()
> > InnerList.Sort(Me)
> > End Sub
> > End Class
> >
> > <Serializable()> Public Class clsFile
> > Inherits clsItem
> >
> > Public Category As String
> > Public FileName As String
> > Public Description As String
> > End Class
> >
> > Public Class FileCollection
> > Inherits CollectionBase
> >
> > Default Public ReadOnly Property Item(ByVal index As Integer) As
> > clsFile
> > Get
> > Return CType(List(index), clsFile)
> > End Get
> > End Property
> >
> > Public Function Add(ByVal item As clsFile) As Integer
> > Return List.Add(item)
> > End Function
> >
> > Public Sub Insert(ByVal index As Integer, ByVal item As clsFile)
> > List.Insert(index, item)
> > End Sub
> >
> > Public Sub Remove(ByVal item As clsFile)
> > List.Remove(item)
> > End Sub
> >
> > Public Function IndexOf(ByVal item As clsFile) As Integer
> > Return List.IndexOf(item)
> > End Function
> >
> > Public Sub Sort()
> > InnerList.Sort(Me)
> > End Sub
> > End Class
> >
> > Now isn't there some way that I can create just an ItemCollection instead
> > of
> > having to create a CategoryCollection, a FileCollection, and so on for
> > every
> > new class I create?
> >
> > --
> > Alex C. Barberi
> > Chief Executive Officer
> > VisionForce
> > http://www.visionforceweb.com
> >
>
>
>

Re: Advanced OOP Question by cody

cody
Thu Feb 23 04:02:50 CST 2006

there are programs which are able to generate source code for a strong typed
collection given a template and a type. for example the free IDE
sharpdevelop is able to do that.


"Alex C. Barberi" <AlexCBarberi@discussions.microsoft.com> schrieb im
Newsbeitrag news:A31B1581-E196-4501-83D1-FBE366BEAFB9@microsoft.com...
> No good. I'm using VS2002.
>
> --
> Alex C. Barberi
> Chief Executive Officer
> VisionForce
> http://www.visionforceweb.com
>
>
>
> "cody" wrote:
>
>> have a look into generics which come with VS2005.
>>
>> "Alex C. Barberi" <AlexCBarberi@discussions.microsoft.com> schrieb im
>> Newsbeitrag news:A7E54BC4-904E-492E-B52A-14B571B4CAC5@microsoft.com...
>> >I have this:
>> >
>> > Public Class clsItem
>> > Implements IComparer
>> >
>> > Public Name As String
>> >
>> > Public Function Compare(ByVal x As Object, ByVal y As Object) As
>> > Integer
>> > Implements IComparer.Compare
>> > Dim empx As clsItem = DirectCast(x, clsItem)
>> > Dim empy As clsItem = DirectCast(y, clsItem)
>> >
>> > Return String.Compare(empx.Name, empy.Name)
>> > End Function
>> > End Class
>> >
>> > <Serializable()> Public Class clsCategory
>> > Inherits clsItem
>> >
>> > Public SubOf As String
>> > End Class
>> >
>> > Public Class CategoryCollection
>> > Inherits CollectionBase
>> >
>> > Default Public ReadOnly Property Item(ByVal index As Integer) As
>> > clsCategory
>> > Get
>> > Return CType(List(index), clsCategory)
>> > End Get
>> > End Property
>> >
>> > Public Function Add(ByVal item As clsCategory) As Integer
>> > Return List.Add(item)
>> > End Function
>> >
>> > Public Sub Insert(ByVal index As Integer, ByVal item As clsCategory)
>> > List.Insert(index, item)
>> > End Sub
>> >
>> > Public Sub Remove(ByVal item As clsCategory)
>> > List.Remove(item)
>> > End Sub
>> >
>> > Public Function IndexOf(ByVal item As clsCategory) As Integer
>> > Return List.IndexOf(item)
>> > End Function
>> >
>> > Public Sub Sort()
>> > InnerList.Sort(Me)
>> > End Sub
>> > End Class
>> >
>> > <Serializable()> Public Class clsFile
>> > Inherits clsItem
>> >
>> > Public Category As String
>> > Public FileName As String
>> > Public Description As String
>> > End Class
>> >
>> > Public Class FileCollection
>> > Inherits CollectionBase
>> >
>> > Default Public ReadOnly Property Item(ByVal index As Integer) As
>> > clsFile
>> > Get
>> > Return CType(List(index), clsFile)
>> > End Get
>> > End Property
>> >
>> > Public Function Add(ByVal item As clsFile) As Integer
>> > Return List.Add(item)
>> > End Function
>> >
>> > Public Sub Insert(ByVal index As Integer, ByVal item As clsFile)
>> > List.Insert(index, item)
>> > End Sub
>> >
>> > Public Sub Remove(ByVal item As clsFile)
>> > List.Remove(item)
>> > End Sub
>> >
>> > Public Function IndexOf(ByVal item As clsFile) As Integer
>> > Return List.IndexOf(item)
>> > End Function
>> >
>> > Public Sub Sort()
>> > InnerList.Sort(Me)
>> > End Sub
>> > End Class
>> >
>> > Now isn't there some way that I can create just an ItemCollection
>> > instead
>> > of
>> > having to create a CategoryCollection, a FileCollection, and so on for
>> > every
>> > new class I create?
>> >
>> > --
>> > Alex C. Barberi
>> > Chief Executive Officer
>> > VisionForce
>> > http://www.visionforceweb.com
>> >
>>
>>
>>



Re: Advanced OOP Question by Larry

Larry
Thu Feb 23 05:24:45 CST 2006


Alex C. Barberi wrote:
> Now isn't there some way that I can create just an ItemCollection instead of
> having to create a CategoryCollection, a FileCollection, and so on for every
> new class I create?

Since you said you are pre-VS2005, your best option is a code
generation tool such as CodeSmith (that's actually the only one I
know). You will have to write your own templates, most likely, but it's
pretty straightforward.

--
Larry Lard
Replies to group please