Method signature


Method signature

In computer programming, especially object-oriented programming, a method is commonly identified by its unique method signature, which usually includes the method name, and the number, types and order of its parameters.[1] A method signature is the smallest type of a method.

Contents

Examples

C/C++

In C/C++, the method signature is the method name and the number and type of its parameters, but it is possible to have a last parameter that consists of an array of values:

int printf(const char*, ...);

Manipulation of these parameters can be done by using the routines in the standard library header <stdarg.h>.

C#

Similar to the C syntax, C# sees as the method signature its name and the number and type of its parameters, where the last parameter may comprise of an array of values:[2]

void Add(out int sum, params int[] value);
[...]
Add(out sum, 3, 5, 7, 11, -1);  // sum == 25

Java

In the Java programming language, a method signature is the method name and the number and type of its parameters. Return types are not considered to be a part of the method signature.

methodName(parameters) {...};

For example, the following two methods have distinct signatures:

doSomething(int y);
doSomething(String y);

The following two methods do have the same signatures and are considered the same, as only the return value differs. The name of the parameter is not part of the method signature and is ignored by the compiler for checking method uniqueness.

int doSomething(int y) 
String doSomething(int x)

Objective-C

In the Objective-C programming language, method signatures for an object are declared in the interface header file. For example,

- (id)initWithInt:(int)value;

defines a method initWithInt that returns a general object (an id) and takes one integer argument. Objective-C only requires a type in a signature to be explicit when the type is not id; this signature is equivalent:

- initWithInt:(int)value;

References

  1. ^ Paul Leahy. "Method Signature". http://www.about.com/: About.com Guide. http://java.about.com/od/m/g/methodsignature.htm. Retrieved 2011-05-31. "A method signature is part of the method declaration. It is the combination of the method name and the parameter list." 
  2. ^ Mössenböck, Hanspeter (2002-03-25). "Advanced C#: Variable Number of Parameters". http://ssw.jku.at/Teaching/Lectures/CSharp/Tutorial/: Institut für Systemsoftware, Johannes Kepler Universität Linz, Fachbereich Informatik. p. 52. http://ssw.jku.at/Teaching/Lectures/CSharp/Tutorial/Part1.pdf. Retrieved 2011-08-03. 

External links


Wikimedia Foundation. 2010.

Look at other dictionaries:

  • Method overloading — is a feature found in various programming languages such as Ada, C#, C++ and Java that allows the creation of several functions with the same name which differ from each other in terms of the type of the input and the type of the output of the… …   Wikipedia

  • Signature (disambiguation) — A signature is a hand written, stylized version of someone s name.Signature may also mean: NOTOC In computers*Signature block, text automatically appended at the bottom of an e mail message, Usenet article, or forum post. *Method signature, in… …   Wikipedia

  • Method overriding — Method overriding, in object oriented programming, is a language feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its superclasses or parent classes. The… …   Wikipedia

  • Signature files — is a technique applied for document retrieval. The idea behind Signature files is to create a quick and dirty filter that will keep all the documents that match to the queryand hopefully a few ones that do not. The way this is done is by creating …   Wikipedia

  • signature — sig·na·ture n 1 a: the act of signing one s name or of making a mark in lieu thereof b: the name of a person written with his or her own hand to signify that the writing which precedes accords with his or her wishes or intentions c: any mark (as… …   Law dictionary

  • Signature change — is concerned with when the signature of spacetime can change from positive definite (++++) to Lorentzian ( +++).There are several reasons for interest in signature change including:1) In the early universe there might be a transition from… …   Wikipedia

  • Method overriding (programming) — Method overriding, in object oriented programming, is a language feature that allows a subclass to provide a specific implementation of a method that is already provided by one of its superclasses. The implementation in the subclass overrides… …   Wikipedia

  • signature crime — n: any of two or more crimes that involve the use of a method, plan, or modus operandi so distinctive that it logically follows that the crimes must have been committed by the same person ◇ Evidence of other criminal acts is usu. not admissible… …   Law dictionary

  • Method (computer programming) — In object oriented programming, a method is a subroutine (or procedure or function) associated with a class. Methods define the behavior to be exhibited by instances of the associated class at program run time. Methods have the special property… …   Wikipedia

  • Signature tagged mutagenesis — Often abbreviated to STM, Signature Tagged Mutagenesis is a genetic technique used to study gene function. Recent advances in genome sequencing have allowed us to catalogue a large variety of organisms genomes, but the function of the genes they… …   Wikipedia