Hello,
This is a rant on an important subject for those interested in OOP
features in F2x. It asks for opinions mostly.
In F2x we only have single inheritance. This was decided a long time
ago. In cases where multiple inheritance might be useful in some other
languages, one must use embedding instead, meaning adding a (possibly
polymorphic) component to the type declaration, instead of type
extension. I have been trying to think of reasonable guidelines on when
to use inheritance versus embedding but am not doing too well. I thus
ask for opinions/references etc.
Here is an example. There are 4 main types in a given type hierarchy:
1. Point_Pattern, representing a static collection of points (with
specific boundary conditions, almost always periodic) equipped with some
tools to find near neighbours and localize points. This should probably
have a method to Synchronize all points to the same point in "time". The
points are typically the centroids of certain objects, such as
particles/molecules etc.
2. Then we have a Dynamic_Point_Pattern, where the points also have
velocities and may be moved around while maintaining the spatial
localization database (in this case a simple grid of bins/cells).
3 and 4. Finally, we have parallel versions of both type, which
represent (domain) partitioned collections of points,
Parallel_Point_Pattern and Paralell_Dynamic_Point_Pattern.
The question is, how to organize these types well into a type
hierarchy/structure. For example, should Dynamic_Point_Pattern extend
Point_Pattern or embed a polymorphic pointer to an object of type
Point_Pattern?
One possible F2x organization is something like:
TYPE Point_Pattern
CONTAINS
PROCEDURE, PASS :: Synchronize=>SynchronizePP ! This procedure does
nothing
END TYPE
TYPE, EXTENDS(Point_Pattern) :: Dynamic_Point_Pattern
CONTAINS
PROCEDURE :: Synchronize=>SynchronizeDPP
END TYPE
Now we have the parallel versions:
TYPE :: Parallel_Point_Pattern
CLASS(Point_Pattern), ALLOCATABLE :: pp
! In initializer allocate this to be of TYPE(Point_Pattern) if not
already allocated
END TYPE
TYPE, EXTENDS(Parallel_Point_Pattern) :: Parallel_Dynamic_Point_Pattern
! In initializer allocate pp to be of TYPE(Dynamic_Point_Pattern)
ENDTYPE
Hopefully the questions here are evident. The choice of when to inherit
and when to embed is not clear, or is it? With the present choice,
Parallel_Point_Pattern can end up having an embedded point pattern that
is dynamic, which it is obviously not equipped to do. But if I extend
the type Point_Pattern to Parallel_Point_Pattern, then the
Parallel_Dynamic_Point_Pattern has a problem of how it gets to a
Dynamic_Point_Pattern. It seems that Parallel_Dynamic_Point_Pattern
should extend (i.e. use inheritance) both Dynamic_Point_Pattern and
Parallel_Point_Pattern, and this is what cannot be done directly in F2x
(possibly for good reasons).
Things are of course complicated further because one needs to further
use these to construct things like a type representing a collection of
hard particles, which need the point pattern in order to implement
neighbourhood searches, but need to also add additional components.
Any ideas on how to resolve things like this would help. Things like
Design Patterns do not seem to be of use here...
Thanks,
Aleksandar
--
__________________________________
Aleksandar Donev
Complex Materials Theory Group (http://cherrypit.princeton.edu/)
Princeton Materials Institute & Program in Applied and Computational Mathematics
@ Princeton University
Address:
419 Bowen Hall, 70 Prospect Avenue
Princeton University
Princeton, NJ 08540-5211
E-mail: [log in to unmask]
WWW: http://atom.princeton.edu/donev
Phone: (609) 258-2775
Fax: (609) 258-6878
__________________________________
|