Consider the following types.
TYPE, ABSTRACT:: base
...
CONTAINS
SUBROUTINE sanity_check
END SUBROUTINE
END TYPE
TYPE, EXTENDS(base):: concrete1
...
END TYPE
TYPE, EXTENDS(base):: concrete2
...
END TYPE
where ...
indicate some data which is not relevant for the question. The types concrete1
and concrete2
have their constructors defined in the code, and the subroutine sanity_check
is also implemented.
Now, I would like to automatically execute sanity_check
at the end of the constructors of concrete1
and concrete2
. In other words, sanity_check
should be executed at the end of the constructors of any type that extends base
, without the need to call it explicitly in the constructors. This would be useful if other programmers were to write a type that extends base
, to check that all the data has been initialized properly by their extended type, without the need for the programmer to call sanity_check
explicitly.
Is this somehow possible? I have seen that it is possible to define an interface for an abstract type, but I don't know if that can be used to achieve what I describe above (or if it is of any use at all, since an abstract type cannot be instantiated by definition).