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
Northampton, Suffolk County, New York

... 65 years of age or older. The median age is 34 years. For every 100 females there are 91.0 males. For every 100 females age 18 and over, there are 82.9 males. Th ...

 
 
 
This page was created in 28.8 ms