C#
C#

help

Root Question Message

Sev
Sev12/18/2022
❔ does an interface go inside a generic parent class?

using Godot;
using System;

public class StateTemplate : Node
{
    public enum State {
        Null,
        Idle,
        Run,
        Fall,
        Jump,
        Dodge
    }
    [Export]
    private String animation_name;
    public Player Player;

    public void enter()
    {
        Player.AnimSprite.Play(animation_name);
    }
    public void exit()
    {}
    public int processInput(InputEvent @event)
    {
        return (int)State.Null;
    }
    public int doProcess(float delta)
    {
        return (int)State.Null;
    }
    public int processPhysics(float delta)
    {
        return (int)State.Null;
    }
}

here is the parent class for my state machine, all states will have a processInput() and processPhysics, do I create an IState interface inside or outside of parent class? I ask because I am translating this from another language and I think this is a pseudo interface
Angius
Angius12/18/2022
Interfaces are, usually, placed in a separate file
Angius
Angius12/18/2022
Also, as a side note, C# uses PascalCase for method names
Angius
Angius12/18/2022
And lowercase string
Sev
Sev12/18/2022
Alright my next question is where do I implement the interface?
Do I do so in the parent class in code above or do I do it each time for each child class?
Angius
Angius12/18/2022
Whichever you prefer
Angius
Angius12/18/2022
Interfaces are inherited by the children of the class that implements them, though
Angius
Angius12/18/2022
If Foo implements IFoo, then Bar : Foo also implements IFoo
Sev
Sev12/18/2022
makes sense. thanks
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy