Fortran Object Oriented Programming Abstract derived types


Example

An extensible derived type may be abstract

type, abstract :: base_type
end type

Such a derived type may never be instantiated, such as by

type(base_type) t1
allocate(type(base_type) :: t2)

but a polymorphic object may have this as its declared type

class(base_type), allocatable :: t1

or

function f(t1)
  class(base_type) t1
end function

Abstract types may have components and type-bound procedures

type, abstract :: base_type
  integer i
contains
  procedure func
  procedure(func_iface), deferred :: def_func
end type

The procedure def_func is a deferred type-bound procedure with interface func_iface. Such a deferred type-bound procedure must be implemented by each extending type.