ITWissen.info - Tech know how online

Overloading method and function names

In many programming languages, overloading a function or method identifier is a common form of polymorphism and is therefore also referred to as "ad hoc polymorphism". The idea is to assign multiple hulls to an identifier and call the appropriate implementation based on the number and type of the current parameters.

Because of the statically given type information about the current parameters - including the notified object - the use of a polymorphic function or the message to an object can be replaced by the compiler by calling the correct function hull or method. Substitutions and type information evaluations at runtime - dynamic binding - are not required.

Examples are found with the arithmetic functions ("+","-"..etc.); these operators can be understood as binary functions without further ado: a+b = +(a,b). The use with int values leads to a different call than the call with real values.

Class identifier when overloading methods

Class identifier when overloading methods

Functions (outside a class definition) or methods (inside a class definition) are overloaded simply by defining the different implementations. They need to differ only by number or types of arguments - not return value. The set of identifiers is extended by this additional distinguishing feature.

An important use case for overloading methods are the constructors of a class, which all have the same name - the class identifier.

Informations:
Englisch: Overloading method and function names
Updated at: 17.11.2009
#Words: 221
Links: indium (In), method, polymorphism, implementation, current
Translations: DE
Sharing:    

All rights reserved DATACOM Buchverlag GmbH © 2024