Book a Demo

Author Topic: specify inheritance order  (Read 2981 times)

jecole

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
specify inheritance order
« on: August 05, 2006, 05:40:49 pm »
Can someone tell me if it is possible to specify the order of classes inherited by a derived class when forwarding engineering from a model to C++?  For example, I have a class which inherits from two classes, one which is a Qt class.  Qt has a limitation requiring the Qt class to be in the list of inherited classes first:

Correct....
class Item : public QWidget, public InterfaceItem
{...}

Incorrect...
class Item : public InterfaceItem, public QWidget
{...}

I found that if I make the connection in the model to the QWidget class first, then the other class, the forward engineering works correctly.  However, if I forget to make the connection in the correct order, the inheritance order is incorrect.  Even if I reverse engineer the code when written correctly, when I forward engineer it back, the order is flipped, unless of course the connections were made in the correct order to begin with.

I realize it isn't difficult to go and change the connections, but it seems there should be a better way to solve this problem.

Thanks for any help...

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: specify inheritance order
« Reply #1 on: August 06, 2006, 05:31:08 pm »
There's not much that I can really suggest.  The generalizations are not an ordered list (as far as UML is concerned) and even the order you are getting can't be guaranteed.

It may be possible to modify the templates to use two separate lists for class parents (first one for Qt classes, second for other classes) but I think you'll need to create a custom template to do it, and maybe even call an addin to ask it if the parent is a Qt class.

Sorry I can't suggest much else.

jecole

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: specify inheritance order
« Reply #2 on: August 07, 2006, 08:48:40 am »
Thank you for the suggestion, but after mentioning this to a co-worker, I think he figured out a way to solve this problem in case someone comes across the same thing at a later time.

The interface class that I was inheriting from was modeled as a normal class.  Instead, we modeled it as an interface object from the class diagram toolbox - (not as an interface stereotype).  The derived item then implemented the interface, while having a generalization relationship with a QWidget.  The "Class Inherits" template in the code generation templates has a default setting of placing interface classes after other base classes in the list of inherited classes.  Therefore, the base class QWidget appears in the list before the interface.  

The only other issue encountered here after making these changes, was the auto-generation of a destructor for the interface in the derived class.  This is a setting in the code generation dialog.  Right click on a derived class, select Code Generation then advanced.  In the list of options, choose Attribute/Operations and then uncheck - Generate methods for implemented interfaces.  Any methods you want auto-generated can be chosen manually by selecting the derived class, then Element|Advanced|Override Implementation... from the main EA menu.

Hopefully this is helpful if someone comes across the same problem.