Composition vs Inheritance: Performance regarding getComponents vs Inheriting Behavior

Right now I am diagramming out my game’s C++ framework/architecture. Partly to better learn software architecture as a whole but secondly to help prevent nasty anti-patterns and class bloat that tend to plague less experienced software engineers.

Being based on monolithic class hierarchy, UE4 allows both inheritance vs composition based design as far as how objects can be given specific behavior/attributes.

The situation I encountered in my framework is this:

  • I have a AHandheldObject object that has behavior & attributes that allows it to be equipped by AHand.
  • I have an UDualwieldingComponent which has two AHand objects (Left and Right hand).
  • AHand objects can only equip objects of TSubclassOf < AHandheldObject >
  • AHandheldObject is then subclassed into more specific things such as AWeapon (and thus it inherits it’s ability to be held)

However another approach to this problem would be:

–More Composition Version–

  • Create a UHandHeldComponent which encapsulates the ability for said object to be equipped.
  • Have AHandheldObject contain UHandheldComponent or even better" completely eliminate AHandHeldObject class and just give AWeapon the component.
  • Have UDualwieldingComponent/AHand check whether or not a given object has the UHandheldComponent component

My Question:
How much of a performance & efficiency concern is it, to have a class check whether a given Object has a specific Component using getComponents vs just checking a given object’s class. (to determine an objects behavior)

This question is two-fold, both the speed part of accessing the components as well as memory-wise having classes with potentially lots of instanced components.