Object Oriented Help With Collection
Hi all.
I have an object, say Beer. I have two sub classes that inherit from beer, LiteBeer and HeavyBeer.
I have a BeerCollection class that I want to use to hold collections of LiteBeer and HeavyBeer. This works fine, as the add method in the collection adds the item as Beer, but I can still access the child properties if cast it back.
The problem is this: I want the Item method in the collection to return the object as the specific type, not just as a Beer object (code below), so that the object is ready to be used.
VB Code:
Public ReadOnly Property Item(ByVal index As Integer) As Beer
I want something like:
VB Code:
Public ReadOnly Property Item(ByVal index As Integer) As Me.List.Item(0).GetType()
but obviously you can't do this. Is there any way to accomplish this with out making a separate collection for LiteBeer and HeavyBeer?
Thanks