U
U
Uncle Bogdan2021-09-10 19:31:28
OOP
Uncle Bogdan, 2021-09-10 19:31:28

How to implement this system?

Hello experts. I decided to make a game (knowledge of Unity is not needed for the answer).

There is an abstract class UnitBase

public abstract class UnitBase
{
    public void Move(Cell cell)
    {

    }

    public void Attack(Cell cell)
    {
        
    }

    public List<Cell> CalculateVariants()
    {
        var variants = new List<Cell>();


        return variants;
    }
}


Each unit will inherit this class. I wanted to make some get-only properties (eg health, damage, etc.). But why make them abstract if you can make the class non-abstract and there will be no difference (Just public fields Health, Damage, etc.). Well, even if I later want to make some abilities for special units, then I’ll just add this to the classes of these units. What's the catch? And how is it better?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Araya, 2021-09-10
@motkot

The trick is that an object of an abstract class cannot be created, which is what you need.
Well, those who will inherit from it are obliged to implement these methods

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question