I would like to have a public, generic, deferred type-bound procedure
for a type while keeping the specific (deferred) type-bound
procedures private. The idea is to encapsulate the names for the
specific procedures and force clients to use the generic name.
Unfortunately, it would appear that the standard does not support
this style because inherited subclasses are not permitted to see the
private procedure names. I'm hoping that I've misunderstood, since
this is a fairly essential aspect of style for OO programming.
Consider the following module defining an abstract derived type:
module visitor_mod
type, abstract :: AbstractVisitor
contains
procedure (RealInterface), deferred, private :: visitReal
procedure (IntegerInterface), deferred, private :: visitInteger
generic :: visit => visitReal, visitInteger
end type AbstractVisitor
abstract interface
subroutine RealInterface(this, x, shape)
import AbstractVisitor
class (AbstractVisitor) :: this
real :: x(*)
integer :: shape(:)
end subroutine RealInterface
subroutine IntegerInterface(this, i, shape)
import AbstractVisitor
class (AbstractVisitor) :: this
real :: i(*)
integer :: shape(:)
end subroutine IntegerInterface
end interface
end module visitor_mod
! This module attempts to generate an extension of the above class,
but fails
! because one cannot extend the private type bound procedures.
module printer_mod
use visitor_mod
type, abstract, extends(AbstractVisitor) :: AbstractPrinter
end type AbstractPrinter
end module printer_mod
Hopefully I've missed something here and there is a semi-elegant
workaround?
Cheers,
- Tom
|