0

I'm trying to do something as

work (a_father: FATHER)
    do
        if a_father.conforms_to ({DEVELOPER}) then
           a_father.code
        else
           a_father.change_job ({DEVELOPER})
        end
    end

enter image description here enter image description here

the compilation works, but in my implementation @runtime it doesn't pass. What did I mistype?

Pipo
  • 4,653
  • 38
  • 47
  • I don't think that you can change the type of argument you receive. Maybe you could have a `job` attributes in `FATHER` to know if it is a `developer`. – Louis M Jun 28 '19 at 00:16
  • @LouisM thx, but that would be a workaround and adding some trick to get the type of an object, not a type checking. – Pipo Jun 29 '19 at 11:26

2 Answers2

1

The problem in your example is that you are trying to see whether the type FATHER (type of the object a_father) conforms to the type TYPE [DEVELOPER] (the type of the object {DEVELOPER}).

What you should do is:

if a_father.generating_type.is_conforming_to ({DEVELOPER}) then

hence comparing TYPE [FATHER] with TYPE [DEVELOPER].

Note that I would assume that it would work by replacing is_conforming_to by conforms_to, but class TYPE introduced this routine is_conforming_to with a more specific argument type.

Eric Bezault
  • 141
  • 5
  • Thx, why is that so? Seems that there are 2 definitions of conformity check `conforms_to (other: ANY)` `is_conforming_to (other: like Current)` your solution should work but passing through a type comparison. Seems that I'm trying to compare 2 different objects (in nature) an object descendent from FATHER & DEVELOPER, and another of TYPE[DEVELOPER] which are not conform one to the other. Does that make sense for you? maybe you could enhance your answer if thats so... – Pipo Jun 29 '19 at 11:31
  • I'm not sure how you want me to enhance my answer. I already mentioned that you were trying to compare `FATHER` with `TYPE [DEVELOPER]` instead of `TYPE [FATHER]` with `TYPE [DEVELOPER]`. – Eric Bezault Jul 24 '19 at 06:25
1

I'd better use a built-in mechanism to check object type conformance:

if attached {DEVELOPER} a_father as dev then
     dev.code
else
     a_father.rest
end

And use the same approach in the precondition:

attached {RELATED_DB_ENTITY} a_relationship_entity

The object test does what you would like to: it checks that the type of the object attached to argument a_relationship_entity conforms to type RELATED_DB_ENTITY.

Alexander Kogtenkov
  • 5,770
  • 1
  • 27
  • 35