Presentation is loading. Please wait.

Presentation is loading. Please wait.

Support for OOP in Fortran (90 and some 95)

Similar presentations


Presentation on theme: "Support for OOP in Fortran (90 and some 95)"— Presentation transcript:

1 Support for OOP in Fortran (90 and some 95)
By Samuel Robinson

2 Support for OOP in Fortran(90)
~General Characteristics -Backwards compatible with Fortran 77 -Classes are supported (keyword: module) -Supports static and dynamic binding (bdstatic, bdynamic) and heap dynamic variables -Supports polymorphism /dynamic binding (Fortran 95) Support for OOP in Fortran(90)

3 Support for OOP in Fortran (90)
Inheritance -Single – only one member inherits -Selective Single – specifies what to inherit -Single with Local Renaming -Multiple Selective

4 Single Inheritance Module new_class_name Use base_class_name
!make new attribute declarations Contains !declare new member definitions End module new_class_name

5 Selective Single Inheritance
Module new_class_name Use base_class_name; only: list_of_entities !declare new attributes Contains !declare new member definitions End module new_class_name

6 Single Inheritance with Local Renaming
Module new_class_name Use base_class name; local_name=> base_entity_name !new attribute declarations Contains !new member declarations End module new_class_name

7 Multiple Selective Inheritance with Renaming
Module new_class_name Use base1_class_name Use base2_class_name Use base3_class_name; list of entities Use base4_class_name, local_name => base entity name !new member definitions Contains End module new_class_name

8 Examples module student !declares student class INTEGER idnumber
end module student module class !declares student class INTEGER classnumber CHARACTER description end module class module student_information !new class use student use class, only: classnumber end module student_information

9 Examples module student INTEGER idnumber contains subroutine grade
grade = average*4 end subroutine grade end module student module class use student, classnumber =>idnumber end module class Examples

10 Public and Private Source: IncyWincy.com module Room_class
implicit none public type Room private integer :: roomNumber logical, dimension(4) :: walls end type Room integer, parameter :: NORTH =1, SOUTH = 2.. contains

11 This Source: IncyWincy.com
To make sure that a type is given the correct procedure, an object of that type needs to be passed. To do this, give the object the name “this” and make it first argument Ex: Subroutine new_Room (this, roomNumber, N,S, E, W) type(Room) :: this ...

12 Support for OOP in Fortran(95)
Dynamic Binding – lets a single object refer to any member of an inheritance hierarchy and allows a procedure to resolve at run time whch object is being referred to Necessary : id mechanism to keep track of the class of the object and method lookup to select the right procedure to execute

13 Polymorphic Type Source: rsimplifiedRT.cwk type poly_stopwatch private
type(stopwatch), pointer :: s Type (parallel_stopwatch), pointer :: p end type poly_stopwatch

14 Use poly_stopwatch_class
type(stopwatch) s type(parallel_stopwatch) p type(poly_stopwatch) sw call new_stopwatch(s) call new_parallel_stopwatch(p) sw = poly(s) call split(sw, 'bar') call bar() call report(sw, 6) sw = poly(p) call split(sw, 'foo') call foo()

15 Evaluation ~Fortran is object based, but not object oriented.
-Inheritance and run time polymorphism are not directly supported, rather they are emulated. -Different, yet the similar.


Download ppt "Support for OOP in Fortran (90 and some 95)"

Similar presentations


Ads by Google