Should I extract this duplication into a superclass, interface, or separate component?

Personally in gamedev (not just Unity) I find inheritance way too brittle. Games often need to change massively in very weird and unusual ways. I feel like every time I construct an object hierarchy I have just baked in far too much brittleness for absolutely zero benefit.

Some folks argue this is because I am personally inept at making class hierarchies, and that may be true.

But if so, 100% of other class hierarchies I have worked with in gamedev similarly feel excessively irritatingly brittle for no actual good engineering reason.

That’s why I like the Unity component hierarchy.

As far as interfaces, interfaces in Unity are AMAZING!! Did you know you can GetComponent() with an interface? That is so powerful when combined with MonoBehaviors! Check it:

Using Interfaces in Unity3D:

https://discussions.unity.com/t/797745/2

https://discussions.unity.com/t/807699/2

Check Youtube for other tutorials about interfaces and working in Unity3D. It’s a pretty powerful combination.

1 Like