Abstract type

Abstract type

: "This article discusses types with no direct members; see also Abstract data type."In software engineering, an abstract type is a type in a nominative type system which is declared by the programmer, and which has the property that it contains no members which are also not members of some declared subtype. In many object oriented programming languages, abstract types are known as abstract base classes, interfaces, traits, mixins, flavors, or roles. Note that these names refer to different language constructs which are (or may be) used to implement abstract types.

Signifying abstract types

Abstract classes can be created, signified, or simulated in several ways:
* By use of the explicit keyword abstract in the class definition, as in Java.
* By including, in the class definition, one or more methods (called pure virtual functions in C++); methods which the class is declared to accept as part of its protocol, but for which no implementation is provided.
* By inheriting from an abstract type, and not overriding all missing features necessary to complete the class definition.
* In many dynamically typed languages such as Smalltalk, any class which sends a particular method to this, but doesn't implement that method, can be considered abstract. (However, in many such languages, the error is not detected until the class is used, and the message send results in an error such as doesNotUnderstand).

Use of abstract types

Abstract types are an important feature in statically typed OO languages. They do not occur in languages without subtyping. Many dynamically typed languages have no equivalent feature (although the use of duck typing makes abstract types unnecessary); however "traits" are found in some modern dynamically-typed languages.

Many authors argue that classes should be leaf classes (have no subtypes), or else be abstract.

Abstract types are useful in that they can be used to define and enforce a "protocol"; a set of operations which all objects that implement the protocol must support. The fact that many languages disallow instantiation of abstract types (and force subtypes to implement all needed functionality) further ensures program correctness.

Types of abstract types

There are several mechanisms for creating abstract types, which vary based on their capability.
* Full abstract base classes are classes either explicitly declared to be "abstract", or which contain abstract (unimplemented) methods. Except the instantiation capability, they have the same capabilities as a concrete class or type. Full abstract types were present in the earliest versions of C++; and the abstract base class remains the "only" language construct for generating abstract types in C++. A class having only pure virtual methods is often called a pure virtual class; it is necessarily abstract.
** Note: Due to technical issues with multiple inheritance in C++ and other languages; many OO languages sought to restrict inheritance to a single direct base class. In order to support multiple subtyping, several languages added other features which can be used to create abstract types, but with less power than full-blown classes
* Common Lisp Object System includes mixins, based on the Flavors system developed by David Moon for Lisp Machine Lisp. (It should be noted that CLOS uses generic functions, defined apart from classes, rather than member functions defined within the class).
* Java includes interfaces, an abstract type which may contain method signatures and constants (final variables), but no method implementations or non-final data members. Java classes may "implement" multiple interfaces. An abstract class in Java may implement interfaces and define some method signatures while keeping other methods abstract with the "abstract" keyword.
* Traits are a more recent approach to the problem, found in Scala and Perl 6 (there known as "roles"), and proposed as an extension to Smalltalk (wherein the original implementation was developed). Traits are unrestricted in what they include in their definition, and multiple traits may be "composed" into a class definition. However, the composition rules for traits differ from standard inheritance, to avoid the semantic difficulties often associated with multiple inheritance.

External links

* "Types and Programming Languages" by Benjamin Pierce (MIT Press 2002) [http://www.cis.upenn.edu/~bcpierce/tapl/main.html]
* "More Effective C++: 35 New Ways to Improve Your Programs and Designs" by Scott Meyers (1995) ISBN 0-201-63371-X
* [http://web.cecs.pdx.edu/~black/publications/TR_CSE_02-012.pdf Traits: Composable Units of Behavior] by Nathanael Schärli, Stéphane Ducasse, Oscar Nierstrasz and Andrew Black


Wikimedia Foundation. 2010.

Игры ⚽ Нужно решить контрольную?

Look at other dictionaries:

  • Abstract-Type and Scheme-Definition Language — ASDL is also a common misspelling of ADSL. Abstract Type and Scheme Definition Language (ASDL) is a computer language developed as part of ESPRIT project GRASPIN, as a basis for generating language based editors and environments. It combines an… …   Wikipedia

  • Object-oriented Abstract Type Hierarchy — OATH Written in C++ Type library or framework Object oriented Abstract Type Hierarchy (OATH) is a class library for C++ from Texas Instruments. This article was originally based on material from the Free On line Dictionary of Computing, which is… …   Wikipedia

  • Trait (abstract type) — Trait is an abstract type, used as a simple conceptual model for structuring object oriented programs. [http://web.cecs.pdx.edu/ black/publications/TR CSE 02 012.pdf] . Traits are similar to mixins, but may include definitions for class methods.… …   Wikipedia

  • Type system — Type systems Type safety Inferred vs. Manifest Dynamic vs. Static Strong vs. Weak Nominal vs. Structural Dependent typing Duck typing Latent typing Linear typing Uniqueness typing …   Wikipedia

  • Abstract factory pattern — The abstract factory pattern is a software design pattern that provides a way to encapsulate a group of individual factories that have a common theme. In normal usage, the client software creates a concrete implementation of the abstract factory… …   Wikipedia

  • Abstract index notation — is a mathematical notation for tensors and spinors that uses indices to indicate their types, rather than their components in a particular basis. The indices are mere placeholders, not related to any fixed basis, and in particular are non… …   Wikipedia

  • Abstract impressionism — is a type of abstract painting (not to be confused with Abstract Expressionism, a similar but different movement) where small brushstrokes build and structure large paintings. Small brushstrokes exhibit control of large areas, expressing the… …   Wikipedia

  • abstract — ● abstract nom masculin (mot anglais) Résumé d un texte scientifique, d un article de revue. ● abstract (difficultés) nom masculin (mot anglais) Anglicisme Dans une publication savante, résumé d un article, souvent placé en tête de l article lui… …   Encyclopédie Universelle

  • Abstract analytic number theory — is a branch of mathematics which takes the ideas and techniques of classical analytic number theory and applies them to a variety of different mathematical fields. The classical prime number theorem serves as a prototypical example, and the… …   Wikipedia

  • Type I cytokine receptor — Type I cytokine receptors are transmembrane receptors expressed on the surface of cells that recognize and respond to cytokines with four α helical strands. These receptors are also known under the name hemopoietin receptors, and share a common… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”