Ok, please bare with me. //long winded explanation incoming.
Ok so I’m making an Item system for my role-playing game. I want to use a system of inheritance with abstract classes so that I will be able to easily add the items to lists and only allow specific types of item to fill certain variables (such as only putting armour in the players armour slots and weapons in the players weapon slots and not vice versa). at the moment the inheritance works like this:
public abstract class Item
{
public string Name;
}
public abstract class Weapon : Item
{
public int Strength{get; set;}
public Weapon(int strength, string name)
{
Strength = strength;
Name = name;
}
}
public class GodSlayer : Weapon
{
public GodSlayer() : base(10, "God Slayer"){}
}
this works fine for me in terms of functionality but it looks sloppy like i’m mixing up abstract variables and putting them in places I might not need to. I was initially using a getter and setter for the Name variable but couldn’t work out the syntax for basing it in the GodSlayer class. However that’s working at the moment without needing to be getted and setted so I presume I also don’t need it for the Strength variable. basically I also want to know what the purpose of getting and setting is in this context in addition to my other question. I was also earlier using
public abstract string Name();
and
public override string Name()
{
return "God Slayer";
}
this seemed inefficient since I had to use an override function each time I wanted to assign a value to the variable. What’s the difference between these two methods?
sorry for so many questions, just any help clarifying this whole situation and helping me understand the best way to go about this would be very much appreciated.
THANK YOU