Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I denote a pure virtual function in a UML class diagram?

I am a student learning C++. I am creating a UML class diagram for my program that involves inheritance and abstract / concrete classes, but I'm not too sure how I would denote a pure virtual function. Any help is appreciated, thank you!

like image 348
john grey Avatar asked Nov 12 '18 21:11

john grey


People also ask

How do you declare a pure virtual function in a class?

You declare a pure virtual function by using a pure specifier ( = 0 ) in the declaration of a virtual member function in the class declaration. Class A is an abstract class. The compiler would not allow the function declarations A g() or void h(A) , declaration of object a , nor the static cast of b to type A .

How can we represent virtual function in class diagram?

Normally, UML indicates virtual functions via italics.

How do you define a pure virtual function?

A pure virtual function is a virtual function in C++ for which we need not to write any function definition and only we have to declare it. It is declared by assigning 0 in the declaration. An abstract class is a class in C++ which have at least one pure virtual function.


1 Answers

The UML standard does indicate that a behavioral feature (e.g. a method/operation) can have its property isAbstract set to indicate that it is abstract and has no implementation. There is however nothing about how this should be shown in the diagram.

According to uml-diagrams.org and other sources, in older UML versions (1.4.x), an abstract operation was shown with a name in italic or with a textual {abstract} marker following its name. The italic convention was widely used (See also here).

The current UML doesn't use anymore use italic and does not indicate how to represent the isAbstract property. Nevertheless, the {abstract} marker should still be valid.

like image 185
Christophe Avatar answered Sep 30 '22 03:09

Christophe