(j3.2006) Parent component of extension of abstract type
Damian Rouson
damian
Fri Nov 13 00:08:13 EST 2015
> On Nov 12, 2015, at 2:10 PM, Tom Clune <Thomas.L.Clune at nasa.gov> wrote:
>
> Sorry - just realized that I misworded my final point.
>
> I meant to say it would be nice if one could invoke the non-deferred methods in an abstract parent.
Unless, I?m misunderstanding the above sentence, this is already allowed. In the code below, for example, I invoke a non-deferred type-bound procedure on an abstract parent at line 44 and also arguably at lines 18 and 46.
>
> But, the non-deferred methods might invoke a deferred method ?
>
This is a common practice at the heart of several OO design patterns. The Template Method pattern, for example, involves specifying the steps of an algorithm in a series of deferred bindings and then writing a non-deferred type-bound procedure that successively invokes the deferred bindings. The nondeferred_tbp subroutine below is essentially a degenerate template method with only one step in the algorithm it encapsulates.
The Cray, Intel, Portland Group, and GNU compilers all accept the code below so again I?m wondering what the constraint is and whether they?re accepting non-conforming code.
Damian
1 module parent_module
2 implicit none
3 type, abstract :: parent
4 contains
5 procedure(abstract_interface), deferred :: deferred_binding
6 procedure :: nondeferred_tbp
7 end type
8
9 abstract interface
10 subroutine abstract_interface(this)
11 import parent
12 class(parent) :: this
13 end subroutine
14 end interface
15 contains
16 subroutine nondeferred_tbp(this)
17 class(parent) :: this
18 call this%deferred_binding
19 end subroutine
20 end module
21
22 module child_module
23 use parent_module, only : parent
24 implicit none
25 type, extends(parent) :: child
26 contains
27 procedure :: deferred_binding => implementation
28 end type
29 contains
30 subroutine implementation(this)
31 class(child) :: this
32 call this%nondeferred_tbp
33 end subroutine
34 end module
35
36 program main
37 use parent_module, only : parent
38 use child_module, only : child
39 implicit none
40 class(parent), allocatable :: nothing
41 type(child) :: thing
42 allocate(nothing,source=thing)
43 call nothing%deferred_binding
44 call nothing%nondeferred_tbp
45 call thing%deferred_binding
46 call thing%nondeferred_tbp
47 end program
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.j3-fortran.org/pipermail/j3/attachments/20151112/56cbdad4/attachment-0002.html
More information about the J3
mailing list