[Solved] Simplifying a class with similar classes inside [closed]


You could create an Animal base class. You’ll probably want to make it abstract so the only way to instantiate an Animal is by creating a new derived object.

abstract class Animal
{
    public abstract int Rarity { get; }  // Abstract properties must be implemented by derived classes
    public int Amount { get; set; }
}

Then each of your different types of animals can inherit the Animal base class. They’ll each need to override the abstract Rarity property. They’ll each have the Amount property from the Animal class.

class Cat : Animal
{
    public override int Rarity => 32;
}

class Dog : Animal
{
    public override int Rarity => 15;
}

class Tiger : Animal
{
    public override int Rarity => 3;
}

2

solved Simplifying a class with similar classes inside [closed]