Interfaces

Interfaces

Interfaces define a contract that any class or struct that inherits it needs to abide to. In an interface you may define the public setters/getters, methods and events that the inheritors need to implement.

By using an interface you no longer care whether an object has class A, B or C, you only care that you can call a specific method on that object. Interface are useful for very generic functionality such as interaction or damaging.

Example of interfaces:

/// <summary>
/// The interactable interface used to be interact with by an interactor.. 
/// </summary>
public interface IInteractable
{
    bool IsInteractable { get; }
    bool Interact(IInteractor interactor);
    bool Select(IInteractor interactor);
    bool Unselect(IInteractor interactor);
}

/// <summary>
/// The interactor allows you to interact with interactables.
/// </summary>
public interface IInteractor
{
    void AddInteractable(IInteractable interactable);

    void RemoveInteractable(IInteractable interactable);
}

/// <summary>
/// The character interactor has a reference to a character.
/// </summary>
public interface ICharacterInteractor : IInteractor
{
    Character Character { get; }
}