Hiding type-bound procedure of a parent data type in child data type

Hiding type-bound procedure of a parent data type in child data type

I have a parent and a child data type with a generic type-bound procedures as follows:

TYPE ParentType
      PRIVATE
      ...
CONTAINS
      PROCEDURE,PASS,PRIVATE :: MethodA
      PROCEDURE,PASS,PRIVATE :: MethodB
      GENERIC,PUBLIC                  :: GenMethod     => MethodA             , &
                                                                                 MethodB
END TYPE ParentType

TYPE,EXTENDS(ParentType) :: ChildType
      PRIVATE
      ...
CONTAINS
      PROCEDURE,PASS,PRIVATE :: ChildMethodA
      PROCEDURE,PASS,PRIVATE :: ChildMethodB
      GENERIC,PUBLIC                  :: GenMethod     => ChildMethodA             , &
                                                                                 ChildMethodB
END TYPE ChildType

Procedures MethodA and ChildMethodA have the same signatures. So do MethodB and ChildMethodB. Essentially the idea is to overwrite the parent GenMethod generic procedure in ChildType. However, when I declare a ChildType variable and call ChildType%GenMethod the procedure from the parent type is executed instead of that from the ChildType.

My question: Is it possible to somehow "hide" the parent type's GenMethod so that when a client code uses ChildType it will only be aware of the ChildType's overwriting GenMethod?

Thanks for any help,

Jon

5 posts / novo 0
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.

Not in the general case. Whether this is possible conceptually for limited cases depends on whether the type definitions are in the same module.

If ChildMethodA or ChildMethodB are not distiguishable from MethodA and MethodB then you should get a compile error.  See the rules for C1215 in F2008 for the requirements.  If they are distringuishable, then you are not hiding the existing specific bindings behind the generic, but adding to them.

(If the type definitions are in the same module and the procedure that is going to do the overriding has the same characteristics bar the passed object (per 4.5.7.3) then you can simply override the bindings in the parent type.  If the type definitions are in the same module and the procedure that is going to do the overriding has different characteristcs but is not distinguishable under the generic name rules, then you are in trouble.  If the type definitions are in different modules and the procedure that is going to do the overriding is not distinguishable, then you are in trouble.  It would be nice if the language allowed some method for bindings to be overridable in different modules, but not otherwise accessible.)

Thanks. The parent and child types and procedures are in different modules. It looks like the best I can do is to give a different name to the overriding procedure, although the "overridden" procedure is not really overridden and still visible to the client code. This is something I was hoping to avoid accidental calls to this procedure.

Where in the standard does in metion that having a different module for the child would make any difference to inheritance of type bound procedures ?  

Note the specific bindings in the posted code were PRIVATE - my comments were [perhaps a bit too] specific to that.  This doesn't change their inheritance - but it obviously does change their accessibility.  See the last few paragraphs of 4.5.4 in F2008. 

My misinterpretation a few months back (I think it was here, perhaps it was c.l.f) was that inaccessible bindings could be overridden.

Deixar um comentário

Faça login para adicionar um comentário. Não é membro? Inscreva-se hoje mesmo!