Author Topic: Inherit attributes from other classes | Custom Code Template  (Read 2042 times)

jespergain

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Inherit attributes from other classes | Custom Code Template
« on: March 30, 2022, 05:56:35 pm »
Hi all,

I was wondering if it is possible to inherit attributes from other classes and use these inherited attributes for source code generation.
I am fairly new to Enterprise Architect and just started to develop a custom code template for the IEC-61131-3/Structured Text language.

The custom code template works pretty fine already, but I can't figure out how to list inherited attributes from other classes.
I already investigated the Linked Attribute Template from other code templates but can't get the results I hoped for.
An example below:

Class A:             Class B:
AttClassA1         AttClassB1     
AttClassA2         AttClassB2   

Class B inherits from Class A

Now I want to generate code of Class B containing all attributes listed above (so AttClassA1/A2/B1/B2)

Therefore, my question is as follows: Is it possible to list inherited attributes from another class and if so, how can I do this?
Is there a special syntax(code/macro/other templates) that I can use in the Code Template Editor?

I hope my question is clear enough for you all and I am looking forward to your reply!

Kind Regards,

Jesper

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1145
  • Karma: +30/-8
    • View Profile
Re: Inherit attributes from other classes | Custom Code Template
« Reply #1 on: March 30, 2022, 08:55:48 pm »
If the classes are related, for example through a generalization/specialisation,  you can display inherited attributes - please see https://sparxsystems.com/enterprise_architect_user_guide/15.2/modeling/displayinginheritedattribute.html#:~:text=Enable%20Display%20of%20Inherited%20Attributes,%27Override%20Attribute%20Initializers%27%20dialog -  and set values.

I cannot answer the code generation question but I would expect it should be possible.

jespergain

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Inherit attributes from other classes | Custom Code Template
« Reply #2 on: March 31, 2022, 12:07:22 am »
Hello Modesto,

Thanks for your response.

The classes are indeed related trough generalization. I already discovered that you could display inherited attributes but didn't know you could also set other values to these attributes. That is also very helpful so thank you very much.

I also suspect that there is a possibility to generate the inherited attributes to code but can't seem to find how/where. Anyone else got any idea?

Thanks in advance!