Copyright (C) 2000-2012 |
Whole document tree
5.7 Type Abstraction using Signatures
In GNU C++, you can use the keyword
Roughly, signatures are type abstractions or interfaces of classes.
Some other languages have similar facilities. C++ signatures are
related to ML's signatures, Haskell's type classes, definition modules
in Modula-2, interface modules in Modula-3, abstract types in Emerald,
type modules in Trellis/Owl, categories in Scratchpad II, and types in
POOL-I. For a more detailed discussion of signatures, see
Signatures: A Language Extension for Improving Type Abstraction and
Subtype Polymorphism in C++
by Gerald Baumgartner and Vincent F. Russo (Tech report
CSD--TR--95--051, Dept. of Computer Sciences, Purdue University,
August 1995, a slightly improved version appeared in
Software--Practice & Experience, 25(8), pp. 863--889,
August 1995). You can get the tech report by anonymous FTP from
Syntactically, a signature declaration is a collection of
member function declarations and nested type declarations.
For example, this signature declaration defines a new abstract type
Since signature types do not include implementation definitions, you cannot write an instance of a signature directly. Instead, you can define a pointer to any class that contains the required interfaces as a signature pointer. Such a class implements the signature type.
To use a class as an implementation of
For example, suppose that
defines a signature pointer Abstract virtual classes provide somewhat similar facilities in standard C++. There are two main advantages to using signatures instead:
There is one more detail about signatures. A signature declaration can
contain member function definitions as well as member function
declarations. A signature member function with a full definition is
called a default implementation; classes need not contain that
particular interface in order to conform. For example, a
class
whether or not
This document was generated by root on January, 30 2002 using texi2html |