Print

Print


>From my perspective, one of the beauties of Fortran 90 is infact that 
in the majority of cases it is not necessary to define an explicit 
interface and thus there is no need to maintain consistent  
specifications of procedures (public or private) in more than one 
place. Thus I would be disappointed to see the 
compulsory separation of implementation and specification  
(interface). 

Never-the-less Fortran 90 does have a problem with respect to the 
way Modules are implemented which can (and does) lead to very large 
source files.

For example, often, one requires that instances of a derived type be 
declared outside the Module in which the type is defined. But is also 
usually required that the components of the type be invisible to the 
outside. In such circumstances it is necessary that all procedures 
that operate on this type be contained in the Module in which the 
type is defined, thus leading to impractically large source files.

It would seem to me that a mechanisim is required which allows one to 
define a type in one Module (file) as PUBLIC with PRIVATE components 
and to be able to specify other Modules (files) for which the PRIVATE 
components can infact be accessed. This would allow one to partition 
the development of a system into smaller and more managable 
components, while at the same time preserving the OO ideas of 
encapsulation and hiding implementation details.

The following pseudo code in which the new constructs UMBRELLA 
and UNDER are introduced is intended to illustrate my objectives.

In this scheme, the UMBRELLA becomes the unit of "Object Oriented" or 
 "logical" encapsulation and MODULES serve as a convenient means
of partitioning a system. However, there is nothing to stop Modules 
being used in the same way that they are currently.

I have no experience in language design or implementation. What 
follows is from a user perspective, and so would welcome suggestions 
for improvement.

=== Pseudo code follows ===

! ... Define an UMBRELLA (MySystem) which USEs Modules 
!     which may be in different files. The entities within a 
!     Module which is UNDER MySystem are visible (PUBLIC) to 
!     all other entities  within all other Modules which are 
!     also UNDER MySystem.

UMBRELLA MySystem

   ! ... This UMBELLA contains the declaration of the type MyType and
   !     and all the procedures which operate on it.
 
   USE MyTypeModule
   USE MyPublicModuleA
   USE MyPublicModuleB
   USE MyPrivateModuleA
   USE MyPrivateModuleB

END UMBRELLA MySystem

MODULE MyTypeModule

   ! ... Declare that MyTypeModule is UNDER the MySystem UMBRELLA
   
   UNDER MySystem

   PUBLIC

   ! ... MyType is PUBLIC but its components are PRIVATE, except in 
   !     those modules UNDER the MySystem UMBRELLA, where the 
   !     components are PUBLIC.

   TYPE :: MyType

        PRIVATE

        INTEGER :: componentA
        ...

   END TYPE MyType

   ...

END MODULE MyTypeModule


MODULE MyPublicModuleA

   UNDER MySystem
   
   ! ... The following modules are UNDER the MySystem UMBRELLA.

   USE MyTypeModule
   USE MyPrivateModuleA

   ! ... The following modules are "normal" modules

   USE OtherModuleA   

   PUBLIC

CONTAINS 

   SUBROUTINE SubA(x)

      TYPE(MyType), INTENT(IN) :: x
      ...

      ! ... components of x are visible within MyPublicModuleA 
      !     because this module is UNDER the MySystem UMBRELLA
      !     of which MyTypeModule is a part.

      x%componentA = 1
     
     ! ... PrivSubA is visible, again because it is UNDER the 
     !     MySystem UMBRELLA

     CALL PrivSubA(x)

   END SUBROUTINE SubA

   ...

END MODULE MyPublicModuleA

! ... Similar for MyPublicModuleB etc.

MODULE MyPrivateModuleA

   UNDER MySystem

   USE MyTypeModule

   ! ... All subroutines in this module are PRIVATE except in those 
   !     modules UNDER the MySystem UMBRELLA, in which they are
   !     PUBLIC.

   PRIVATE

CONTAINS 

   SUBROUTINE PrivSubA(x)

      TYPE(MyType), INTENT(IN) :: x
      ...

      x%componentA = ...

   END SUBROUTINE PrivSubA

   ...

END MODULE MyPrivateModuleA


! ... Similar for MyPrivateModuleB etc.

MODULE SomeOtherModule

   USE MyTypeModule
   USE MyPublicModuleA

CONTAINS

   SUBROUTINE SomeSub(x)

      TYPE(MyType) :: x

      ! ... The components of x cannot be accessed because 
      !     SomeOtherModule is not UNDER MySystem.
      !     Similarly, PrivSubA can not be called from this Module.
      !     However, SubA can be called because it was declared
      !     to be PUBLIC in MyPublicModuleA.

      CALL SubA(x)

   END SUBROUTINE SomeSub

END MODULE SomeOtherModule

 
Regards,
David.

----------------------------------------------------------

David Vowles
Research Officer
Department of Electrical and Electronic Engineering
The University of Adelaide
Australia 5005

Voice: +61 8 8303 5416
Fax:   +61 8 8303 4360
Email: [log in to unmask]


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%