Interface Implementation on Actor itself vs Component

Hi there guys, thanks for all the help by the way. I’m right now faced with a design choice and i would like to hear your opinions as to which implementation would be better in the long term.

I have an interface called InteractableInterface which simply put, lets some actor be interactable, it has the StartFocus, EndFocus and Interfact methods.

My idea was to originally implement this interface on the actor itself creating a InteractableActor which the other actors in the world could inherit from and then override the methods on it for specific implementations. Default method would be to highlight the actor when on focus and stop highlighting when out of focus.
But it also came to mind the power of components, and how it’s always prefered to use composition vs inheritance. So the other option would be to create different components which implements this interface and attach them to the actor, this component could be HighlightsOnFocusComponent, etc…

For me, the inheritance path looks way clearer, and won’t let multiple components that implmeent the interface be attached to the actor which would be a nightmare to debug.

Also i would have to change the way the events are triggered, because right now i’m looking if the actor implements the interface, but i should look for all the components of the actor who implement the interface.

My question is, maybe there is some clearer way i’m not thinking right now? should i just go with inheritance? or is it prefered to use composition in cases like this??

greetings!

1 Like