Book a Demo

Author Topic: C++ virtual method shown in italic  (Read 3899 times)

tletsch

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
C++ virtual method shown in italic
« on: January 30, 2010, 01:38:13 am »
Hello

If for a C++-class a method is set to 'Virtual', this method is than shown in 'italic' in the class diagram.

This is surprising, because italic are commonly used for abstract classes or methods (and 'virtual' does not mean 'abstract', which in C++ would be 'pure virtual' -> '= 0').

See also the corresponding thread in "Bugs and Issues">"C++ virtual method shown italic?" (Jan 22nd, 2010, 11:06am).

I do also some teaching: for students/beginners it is quite confusing.


For that, I would suggest virtual-methods to show with normal letters, NOT ITALIC.


Thanks
Thomas

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: C++ virtual method shown in italic
« Reply #1 on: January 30, 2010, 02:53:53 am »
I've mentioned in the other thread, what the UML 2.2 Superstructure definition tells us about this convention(?): Nothing!
It recommends to use italic fonts for abstract classifier names, but there's no notion given about how to render names of operations.
Pure virtual methods, like they are used in C++, are a language specific concept, and thus,- I guess -, not considered by UML at all. There's not even an attribute (like e.g. 'isAbstract' for classfiers) provided for operations.
Many (more modern?) languages, like Java, C# and others introduce the concept of interfaces or allow to specify operation signatures as 'delegates' (function pointer type definitions in C++), which focuses the problem more clearly IMHO: It's about definition of contracts.
I'd recommend to teach your students the problem domain (interfaces/contracts) first and afterwards how to implement it properly in UML / C++, and maybe mention other languages.
C++ "lacks" an intrinsic way to express what is an interface, other languages don't provide a concept of 'abstract' operation definitions. So go to the meta level to put it from an abstract point of view.

BTW, I personally find the 'italic' rendering for virtual and abstract methods very useful in practice. Because what I'm usually interested in, when looking at a diagram for extension of the model, is which methods can be overridden. For that it doesn't matter at least if these were defined as virtual or pure virtual.

HTH
Günther