I'm not sure what I think on this topic.
I first preferred inheritance for something like this...
- Cloth (inherited of class Item)
- // etc. etc.
Then, I had a collection: m_items<Item>
I'd store everything into m_items: cloth, item, weapon, etc.
Then, I'd do a foreach on each Item. Well, they're now of type Item. I don't know what's what.
There is a way of determining the type by using OfType<DataType>() in a foreach, but after making 3-4 foreach'es, it defeats the purpose of something clean and elegant.
Being a little lost, I wanted to just do composites (without inheritance) thinking it would be cleaner. I'm a little annoyed with adding new functions, like AddCloth(), AddWeapon(), etc. with a linked list to each type, rather than just AddItem(Item). I'm also assuming this means I'm losing the data of the inherited type, since it's storing Item, not Cloth, Weapon, etc. with their own properties.
Of course, adding an item to an multidimensional cell of type linkedlist is easier with inheritance. Trying to search it and find out what inherited type Item is, and still retaining the inherited data, is probably my biggest issue I'm wondering on.
Is there a recommended way with adding and searching through items? I wonder if it's just a trade-off matter.
Edited by shinypixel, 07 June 2014 - 02:55 PM.