0

Repeatedly inheriting from 2 classes having the same parent, I fall into the classic case of inheriting 2 times of the same attribute. I'd like to merge the 2 attributes into one and tried to do it with an undefine, but it gets me a compile error. The other solution I see is renaming the attribute from one of both parents, but as I understand each instance of my D class would have an useless attribute which is not what I want...

Error: Undefine subclause lists name of frozen feature or attribute or C external. What to do: unless you can change the status of the feature in the parent, remove its name from Undefine subclause since it cannot be undefined.

How to merge 2 attributes from repeatedly inherited classes

class A
    serial: STRING

end -- class A

class B

inherit
    A

end -- class B


class C

inherit
    A

end -- class C


class D

inherit
    B
        undefine 
            serial -- error seems to appear here in that case
        end
    C

end -- class D
Pipo
  • 4,653
  • 38
  • 47

2 Answers2

1

There is no reason to undefine a feature that is going to be merged with the same version coming from a different inheritance path. In the example, the attribute serial is not changed in B, C, and D. Therefore, inheriting from B and C without any adaptation is OK:

class D inherit
    B
    C
end
Alexander Kogtenkov
  • 5,770
  • 1
  • 27
  • 35
  • Sorry, I think I was unclear in my question, I edited it hope I'm more this time – Pipo Oct 15 '19 at 09:01
  • @Pipo The answer remains the same: just keep the attribute under the same name, it will be merged into the one without an error. – Alexander Kogtenkov Oct 15 '19 at 10:32
  • Eric gave me the reason, my example was not complete as I renamed the attribute into class B! renaming to serial again into D and redefining it gave me the solution! – Pipo Oct 15 '19 at 18:19
  • @Pipo I would suggest editing the question to reflect the problem you were facing. My answer addresses a completely different issue stated in the original question. – Alexander Kogtenkov Oct 16 '19 at 08:12
  • yes, but then you'll have to edit your answer, so I don't want you having to edit your whole answer, that was the reason I didn't want to edit it – Pipo Oct 16 '19 at 09:47
1

In case it's two unrelated attributes (not coming from the same parent) that you want to merge, you should redefine both of them:

class A
feature
    serial: STRING
end

class B
feature
    serial: STRING
end

class C
inherit
    A
         redefine
               serial
         end
    B
         redefine
               serial
         end
feature
    serial: STRING
end

As you already saw, the compiler will not let you undefine an attribute, even when the goal is to merge it with another attribute.

Eric Bezault
  • 141
  • 5