Extensible derived types (Fortran 2003)

An extensible type is a nonsequence noninteroperable derived type from which you can extend new types. You cannot use record structure syntax to define an extensible type. You can further classify an extensible type to be one or more of the following:
Base type
Extends only itself and no other types.
Extended type
Extends not only itself, but all types for which its parent type is an extension.
Parent type
Provides components and procedure bindings to all types that extend from that type. A parent type is the extensible type from which an extended type is derived

You define an extended type with the EXTENDS attribute. The EXTENDS attribute specification includes the name of the parent type. For more information on specifying the EXTENDS attribute see TYPE.

An extended type inherits all of the type parameters, components and nonoverridden, nonfinal procedure bindings from its parent type.

The extended type also inherits inaccessible components and bindings from the parent type. They remain inaccessible in the extended type. A private entity is inaccessible if the type that you extend is accessed through use association.

A base type is not required to have any type parameters, components or bindings. An extended type is not required to have more type parameters, components or bindings than its parent type.

A type is not required to use any type parameters it or any parent may have defined.

An extended type has a scalar, nonpointer, nonallocatable, parent component with the same type and type parameters as its parent type. The name of this component is identical to the name of the parent type, and has the same accessibility.

A type parameter or component declared in an extended type must not have the same name as any type parameter or component of its parent type.

Example of an extended type


TYPE :: POINT ! A base type
   REAL :: X, Y
END TYPE POINT

TYPE, EXTENDS(POINT) :: COLOR_POINT ! An extension of TYPE(POINT)
   INTEGER :: COLOR                 ! Components X and Y, and component name 
END TYPE COLOR_POINT                ! POINT, inherited from parent

In the example, the type COLOR_POINT inherits the components X and Y from parent type POINT. The components retain all of the attributes they have in the parent type. You can declare additional components and procedure bindings in the derived type definition of the extended type. In the example of an extensible type, the type COLOR_POINT has one additional component, COLOR. The type POINT is a nonsequence type that is not an extension of another type and therefore a base type. The type COLOR_POINT is an extended type, whose parent type is POINT.

COLOR_POINT has a parent component POINT. The parent component, POINT, is a structure with the components X and Y. Components of the parent are inheritance associated with the corresponding components inherited from the parent type. An ancestor component of a type is the parent component of the type or an ancestor component of the parent component. The ancestor component of COLOR_POINT is the parent component POINT.

For code example of type parameters, see the Type Declaration section.