Type signature

A signature (or signature methods ) defined in the programming of the formal interface of a function or procedure. It consists of the name of the function and the number and order of the allocation parameter compatible data types. The type of the return value also belongs in rigidly structured programming for signature.

The amount of the operators is an abstract data type called a signature.

Under Signature Inheritance is in the object -oriented programming, the transmission of a defined in the superclass (and possibly implemented ) method on the subclass.

Return type

In Pascal and C derivatives, and similar languages ​​, which are not taken into account when overloads the return type can not be distinguished, which method should be used in a specific application.

Example:

...       / / Declaration      float parts (int dividend, int divisor ); / / The signature is here: parts (int, int)      double parts ( int a, int b); / / Not allowed, signature is the same as above: parts (int, int)      ... Both methods or functions above have the same signature.

...       / / Declaration       boolean isNegativ (float number ); / / The signature is isNegativ (float)       boolean isNegativ (double number ); / / Ok, signature is different: isNegativ (double)       ... Now could not be decided which parts function (int, int) should be used in a specific application:

...      / / The above functions are to be used here:      boolean b = isNegativ ( components ( x, y) ); / / Float parts ( ..) or double share ( ..)?       ... In contrast, the possibility can be given explicitly in terms of a type specified. This allows the call target to be specified clearly. Haskell makes use of this. For example, yield the expressions

Read " 42 " :: Integer and

Read " 42 " :: Double different values ​​of different types.

Object orientation

In object-oriented programming, a signature is the formal interface of a method.

Signatures play a role in the polymorphism, one of the basic concepts of object orientation. In many programming languages, a method of a derived class, a base class method if and only overwrite if the signatures of the two methods are identical.

Overridden methods

In the following Java example the method signatures of the upper class and derived class seem to be the same: "String redemit (String) ". For the compiler, however, the methods have different signatures, because it still takes into account the associated namespaces and class types. The method of the derived class has here the method of the base class overridden (English override ). Here is an example:

/ / Superclass class Person {        Redemit String (String name) {        return " Hello " name;      } }   / / Derived class. Superclass relation implies supertype relation. Nice Person class extends Person {        / / Method redemit (String) is overwritten      Redemit String (String name) {          return " Nice to see you, " name;      } }   public class Main {        public static void main ( String [ ] args ) {            Person p;            / / Here can be decided only at run time, which method should be taken.          if ( 0.5 < Math.random ()) {              p = new Person (); / / Original person p          Else { }              Nice Person p = new (); / / Person p is instantiated with " nice " behavior.          }            for ( String name: args) {              System.out.println ( p.redeMit (name) "." );          }      } } At runtime, each object returns a pointer to a table with virtual methods that exist for each class. This pointer is initialized during object instantiation and enables polymorphism, ie rewritable behavior.

Subclass instances can optionally access by means of so -called super pointer to the overridden methods of their superclasses.

Class signature

The set of all signatures defined the public interface of a class.

Internal representation in programming languages

Many C compilers form of the name of a function or method and the encoded signature known as a decorated function names (English mangled name). This composite name forms the linker symbol. This can prevent that functions with the same name but different signatures are falsely linked by the linker. The names of the methods listed in addition to the class name. However, the decorated function names are to be interpreted only for the appropriate compiler and linker, as the following example shows:

? seekpos @? $ basic_streambuf @ DU? $ char_traits @ D @ std @ @ @ std @ @ MAE? AV? FPOS $ @ H @ 2 @ V32 @ H @ Z? seekpos @? $ basic_streambuf @ GU? $ char_traits @ G @ std @ @ @ std @ @ MAE? AV? FPOS $ @ H @ 2 @ V32 @ H @ Z In the Java language also exists an internal representation of method names, the so-called method descriptor. Unlike C , this part of the language specification, and thus the same for all compilers and virtual machines. The following example shows the internal form of the signature of the method " Object my method ( int i, double d, Thread t)."

( IDLjava / lang / Thread ;) Ljava / lang / Object; swell

566478
de