Print

Print


I'm seeking some methodology/style advice.

I have a need for "arrays" of polymorphic values of differing
dynamic type.  A polymorphic array is not an option since its
elements have homogeneous dynamic type.  The standard
workaround seems to be boxing a pointer to a polymorphic scalar
and then working with arrays of the box type; e.g.

  type :: box
    class(foo), pointer :: ptr
  end type
  type(box) :: array(10)

This works fine of course, but it's clumsy and hard to explain
how to use to less sophisticated developers who find it obtuse.
For example, to construct an array out of polymorphic pointers
x and y one needs to write (/ box(x), box(y) /).

Is there some general strategy for hiding this workaround?
Some different design viewpoint that is easier to document
and explain.  Perhaps treating variables of the box type
as the central objects rather than the polymorphic variables
themselves?

-Neil

-- 
Neil N. Carlson <[log in to unmask]>