Share

Polymorphism and overloading

Polymorphism is implemented by creating multiple versions of the same node, but with different input types and different internal implementations.

Sets of multiple versions of the same node are called overload sets. The members of an overload set do not need to be distributed in the same pack. They can be compounds, operators or a combination of both.

All the nodes in an overload set must:

  • Have the same name
  • Have the same number of input parameters
  • Have the same number of output parameters
  • Have the same names for their input and output parameters
  • Have their parameters appear in the same order in their signature
  • Have different input types from the other members of the set

When a member of an overload set is added to a Bifrost graph, all that is known about it is its name, and the names of its ports. Only once the node is connected will the compiler know which specific member of the overload set to use.

Until then, any ports that can accept different inputs will appear as auto ports. However, if there is a version of the set that you expect will be used most often, you can specify a default version of the node to instantiate using the DefaultOverload annotation if this version is an operator written with the Bifrost Operator SDK.

Once connections are made to the node, the node will resolve to the best-matching candidate from its overload set. If there are no suitable matches in the overload set, the compiler will generate an error.

See sdk/examples/HSV in your installation for an example of overloading a set of nodes.

Was this information helpful?