I have a class called BagItem
and another class called EquipmentItem
both classes are exact the same in methods, etc, with the exception of 1 property.
BagItem
have:
public InventoryBagType BagType { get; private set; }
EquipmentItem
have:
public InventoryEquipmentType EquipmentType { get; private set; }
I guess I should mention, BagItem
refer to items that are in the character's bag while EquipmentItem
I should have probably named it EquippedItem
which refer to item currently equipped by the character.
From those 2 classes I have other classes that inherit from one or another.
Then from EquipmentItem
for example I have CombatEquipmentItem
which inherits from EquipmentItem
and CombatEquipmentItem
only have one extra property.
public CombatEquipmentType SlotType { get; private set; }
At this point I don't know if CombatEquipmentItem
will have or not more properties or methods, neither if either BagItem
or EquipmentItem
will either.
I was considering creating yet another class InventoryItem
that would keep all the common entries from BagItem
and EquipmentItem
and they would inherit from it and by its turn CombatEquipmentItem
from it.
Should I eliminate BagItem
and EquipmentItem
for InventoryItem
and keep both the properties there and either set one or another as null based on the item and inherit anything else from it or should I move forward with yet another class or my design is bad from the begin and how it should have been written as?
BagItem
andEquipmentItem
. Inheritance will fail you at that point.have a bag inside bag
could you elaborate a bit on that? Technically if I make InventoryItem and make both inherit from it, it would be true that both are an inventoryitem but further also something else, i.e a equipmentitem or bagitem. I originally made it this way so I could easily do something likeEquippedItems.OfType<CombatEquipment>()
but since technicallyequipmentitem
andbagitem
dont inherit from anything yet have everything the same except for a property updating both all the time became out of way.EquipmentItem
object? What happens to the oldBagItem
object?BagItem
to theEquipmentItem
, or are the relevant fields copied one by one? If, for example, the player is equipping an helmet, is the sameHelmet
object being referred from both the deletedBagItem
and the newEquipmentItem
, or are you creating a newEquipmentHelmet
object from the oldBagHelmet
object that'll be deleted after?