Book a Demo

Author Topic: Code Generation: override and virtual  (Read 3568 times)

StefanR

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Code Generation: override and virtual
« on: May 28, 2004, 04:42:26 am »
There are some problems when generating source code from class diagrams in Delphi. Following scenario:

class A has virtual method doSth()
class B inherits from A and overrides doSth()

The generated code should look like this:
Code: [Select]

type
 A = class
 public:
   procedure doSth; virtual;
 end;
 
 B = class (A)
 public
    procedure doSth;override;
 end;


First of all, it is not possible to set the operation-property 'pure' without enabling 'abstract'. ('pure' leads to 'virtual'-keyword on code but an 'abstract'-keyword is not wanted here)

Secondly, the keyword 'override' is never generated although it must not be omitted do have the desired functionality.

I wonder if the template-script-language is powerful enough to write a 'override'-keyword when necessary? If not, this might become an important feature for a future version...

Regards,
Stefan.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Code Generation: override and virtual
« Reply #1 on: May 30, 2004, 05:52:31 pm »
Hi Stefan,

I can modify the operations dialogue so that it doesn't automatically check abstract when you select pure when using Delphi.  Only, is this what you actually need?

I could also write a function macro for the templates so that it checks where the operation is from.  This could take a variety of different forms such as reporting the class and things such as the function is pure or whatever.  I think this is an option more for the future though so that I can make it as usable and useful as possible.

I'll give another recommendation though if it meets your needs.  C# currently relies on a tagged value for using the 'override' keyword.  That tag is actually created and set using the advanced button in the operations dialogue, you can use the same thing without that though.  Just add the following line to the code template:

%opTag:"override" == "true" ? "; override" : ""%

I'll look into adding the advanced button the the delphi dialogue to make using this easier.  If I do, what other delphi keywords should be added to it?

Simon.

StefanR

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Code Generation: override and virtual
« Reply #2 on: June 02, 2004, 01:02:06 am »
Hi Simon,

thanks very much for your help!
Quote
I can modify the operations dialogue so that it doesn't automatically check abstract when you select pure when using Delphi.  Only, is this what you actually need?

Yes. Usability would also be greatly enhanced when the pure-buttons' caption is renamed to 'virtual' when Delphi is chosen as language.

Concerning the generation of keywords like virtual, override, etc. I would propose following: One should have the possiblilty to view and edit these properties for each operation within the edit-mask. This is essential because in most cases you override a virtual method (for example), but sometimes you may want to hide it only! The advanced-button when using C# is a possibility. Maybe a language-specific edit-mask performs even better, as you will always have keywords which exist in one language but not in another. However, this probably causes a bigger effort to implement  :-/

Additionally, the checkboxes should be autochecked: Whenever a method is declared as virtual, all inherited methods should be marked as override.

In my opinion, following keywords are necessary:
virtual
override
overload (whenever a method is overloaded)
reintroduce (whenever a method explicitly hides a virtual method from a parent class instead of overriding it)

I hope this haven't been to many wishes at once :-)
Regards,
Stefan.