Quote: Original post by popcorn
I'm not quite sure I understand this yet though so I may resort to something simpler but I would like to ask if you create an item class and derive a weapon and armor class from it - how would you create the handle class for this - does the interface for the handle class have to provide all the member functions that the item class as well as the derived classes have?
Only if you derive the handle class from the the weapon or armor class. Then yes it will include all the methods of the Item and Weapon/Armor classes. You can hide methods in the Weapon/Armor classes by declaring those methods private. Your Handle class would not see or be able to use those methods then. Same goes for the Item class, but those methods would not only be hidden from the Handle class but from the Weapon/Armor classes aswell.
I think that a handle class would be unecesary. Once you derive a weapon and armor class from an item class then you can treat those objects created as generic items that can be held in a container of <Items> to be found or carried as in a backpack. Then to invoke "use or handle" simply add the wanted item to a container of <Weapon> or <Armor> in a character class object. The Weapon and Armor Classes will have all of the methods defined in the base class <Item> available to them. Add the method of use to the Weapon and Armor Classes directly. That is, if the only time the weapon and armor mods will be available is during combat... that way all you have to do is call those methods in your combat resolving code when you need the stats to apply.
You can take this further... say you wanted to loot weapons and armor off of an enemy player. You can create a method that upon death the weapon and armor objects would be moved to an inspectable <Item> container in the enemy character object. Upon looting move that object to the player's <Item> container.
Things like potions that are usable would work the same way. They would have all the methods defined in the base Item class, but their methods of use would be defined directly in the Potions class. Just like Weapons and Armor, they could be stored in a container of <Item> to be used. To distinguish wether or not something is useable...a potion is usable out of the backpack, where Weapons and Armor have to be equiped, just place a bool isuseable=(true/false) in your base item class.