Multiple dispatch
Before we dive deep into the topic, let's just ask ourselves a quick question. What does dispatch mean? To come up with an answer in the easiest of terms, we can say that dispatch means to send!
In programming terms, dispatch means to send a message to a listener or a call to a function. Basically, to send a piece of data (or packet of information) to code that is ready to handle it.
Dispatch can be of many different types. Starting off with a few of them we have:
Static dispatch: The dispatch order can be defined at compile time. Essentially, in static dispatch, all types are already known before the execution of the program. Compiler is able to generate specific code for every possible combination of datatypes and know in advance when and where they will be used. This is one of the most common in most languages. To break it down, if we have a place in the code where the function or a method is called usingÂ
funct()
or perhapsÂx.funct()
, then that very same function will be...