Encyclopedia > Multimethods

  Article Content

Multimethods

It's convenient for programmers to be able in their code to give different blocks of code the same name.

How is this achieved?

Code can be divided into modules, with some blocks being private or public. Private blocks in different modules can be given the same name.

Some programming languages allow overloading, where a block in the current scope hides blocks with the same name in outer scopes. Although blocks can be given the same name, only one at a time is ever available. Examples are method overloading in object oriented programming languages, and functions declared inside functions in procedural programming languages.

Namespaces allow public blocks residing in different modules to share the same name. Where there is ambiguity, the block's name is qualified by it's namespace.

Multimethods allow multiple code blocks to be in the same scope at the same time, and use some or all of the signature of the block to disambiguate.

The signature of a function or method is comprised of it's return type, it's name, and the types and number of it's parameters.

In the programming language C, 'int add(int, int)' and 'float add(float, float)' cannot be in the same scope together, although the signatures are different, in both their parameters and their return type.

In some programming languages, the value of parameters are also used to disambiguate.



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
Dynabee

... the thumb, a person holding it in her hand can accelerate the gyroscope to incredibly high revs by following a circular wrist motion with the device. Modern devices come ...

 
 
 
This page was created in 33.2 ms