Fortran 2003 introduced several object-oriented programming features, including:
- Derived Type Extension: Allows you to define a new type that extends an existing type using extends.
- Type-bound Procedures: Functions or procedures bound to a specific type, which can be overridden in derived types.
- Inheritance and Polymorphism: Supports polymorphic types and inheritance, enabling object-oriented design patterns.
- Interfaces for Type-bound Procedures: Using procedure and interface blocks within derived types for defining virtual functions and interfaces.
Example from source:
type, extends(shape_m), public :: triangle_m
contains
procedure :: get_area
end type triangle_m
type, extends(shape_m), public :: triangle_m
: Definestriangle_m
as a derived type that extendsshape_m
, inheriting its properties and methods.contains
andprocedure :: get_area
:contains
signifies thattriangle_m
will have type-bound procedures, andprocedure :: get_area
binds theget_area
procedure to this type, which overridea theget_area
inshape_m
if it exists there.