10.07.2015 Views

PGI Fortran Reference manual - The Portland Group

PGI Fortran Reference manual - The Portland Group

PGI Fortran Reference manual - The Portland Group

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 7.OBJECT ORIENTED PROGRAMMINGObject-oriented programming, OOP, describes an approach to programming where a programis viewed as a collection of interacting, but mostly independent software components. <strong>The</strong>sesoftware components, known as objects, are typically implemented as an entity that encapsulatesboth data and procedures. Object-oriented programming focuses on the data structures; that is,focus is on the objects on which the program operates rather than the procedures. In languagesdesigned to be object-oriented, there are classes, containing both data and modules, that operateon that data. In <strong>Fortran</strong>, modules may contain data, but there is no notion of separate instances ofa module. However, in <strong>Fortran</strong> 2003, there are type extensions and type-bound procedures thatsupport an object-oriented approach. To have ‘class-like’ behavior, you can combine a module,which contains the methods that operate on the ‘class’, with a derived type containing the data.<strong>PGI</strong> <strong>Fortran</strong> compilers contain procedures, functions, and attributes from <strong>Fortran</strong> 2003 thatfacilitate an object-oriented approach to programming. Some of the object-oriented featuresinclude classes, type extensions, polymorphic entities, typed allocation, sourced allocation,inheritance association, as well as object-oriented intrinsics. This section provides a high-leveloverview of these features.TipFor specific information on how to use these extensions and for examples, refer to one of the many reportsand texts available, such as these:‣ Object-Oriented Programming in <strong>Fortran</strong> 2003, <strong>PGI</strong> Insider, February 2011‣ <strong>The</strong> <strong>Fortran</strong> 2003 Handbook: <strong>The</strong> Complete Syntax, Features and Procedures by Adams, J.C.,Brainerd, W.S., Hendrickson, R.A., Maine, R.E., Martin, J.T., Smith, B.T‣ <strong>Fortran</strong> 95/2003 explained by Metcalf,m., Reid, J., and Cohen, M.7.1. InheritanceInheritance allows code reusability through an implied inheritance link in which leaf objects,known as children, reuse components from their parent and ancestor objects.For example, the following code shows how a square type inherits components from rectanglewhich inherits components from shape.<strong>PGI</strong> <strong>Fortran</strong> <strong>Reference</strong> Guide 121

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!