Fortran Object Oriented Programming Derived type definition


Example

Fortran 2003 introduced support for object oriented programming. This feature allows to take advantage of modern programming techniques. Derived types are defined with the following form:

TYPE [[, attr-list] :: ] name [(name-list)]
   [def-stmts]
   [PRIVATE statement or SEQUENCE statement]. . .
   [component-definition]. . .
   [procedure-part]
END TYPE [name]

where,

  • attr-list - a list of attribute specifiers
  • name - the name of derived data type
  • name-list - a list of type parameter names separated by commas
  • def-stmts - one or more INTEGER declarations of the type parameters named in the name-list
  • component-definition - one or more type declaration statements or procedure pointer statements defining the component of derived type
  • procedure-part - a CONTAINS statement, optionally followed by a PRIVATE statement, and one or more procedure binding statements

Example:

type shape
    integer :: color
end type shape