Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I draw C++ concepts in UML class diagram?

How would I draw C++ concepts in an UML class diagram?

Specifically, I have the following code:

template<typename T>
concept Printable = requires(T a, std::ostream &where) {
    { where << a };
};

template<typename T>
concept Identifiable = requires(T a) {
    { a.getId() } -> std::convertible_to<std::string>;
};

template<typename T>
concept Listable = Identifiable<T> && Printable<T>;

and then a class:

template<Listable T>
class Liste {
    ...
    void add(T *data);
    ...
}

If it were a regular template, I would just put the T in a square in the corner of the class. But what about the concepts?

like image 616
Finn Avatar asked Sep 17 '20 18:09

Finn


People also ask

What is UML class diagram?

UML Class Diagram Tutorial The UML Class diagram is a graphical notation used to construct and visualize object oriented systems. A class diagram in the Unified Modeling Language (UML) is a type of static structure diagram that describes the structure of a system by showing the system's:

What is the UML shape library in LucidChart?

The UML shape library in Lucidchart can help you create nearly any custom class diagram using our UML diagram tool. Class diagrams offer a number of benefits for any organization. Use UML class diagrams to: Illustrate data models for information systems, no matter how simple or complex.

What is the importance of class notation in UML?

It also illustrates the operations and attributes of the classes. They are usually used to explore domain concepts, understand software requirements and describe detailed designs. There are several class diagram notations that are used when drawing UML class diagrams.

What is class diagram in C++?

Class Diagram helps construct the code for the software application development. Class Diagram defines the types of objects in the system and the different types of relationships that exist among them. It gives a high-level view of an application.


Video Answer


1 Answers

The C++ concepts defines constraints on the types associated with a template class:

  • Since UML supports class template, you would typically express this constraints for its parameters, between curly brackets, either in natural language or in OCL. The former is perfect at an early design stage. But you could as well consider to pragmatically express it using the same syntax than C++ instead of natural language, if you need this level of accuracy.

  • Alternatively, you may as well handle the C++ concept as a kind of generic type in UML. You could then use the concept in a much more readable way in the the type definition of the template parameters in class templates. This would be more convenient to read, and closer to the C++ idea. The problem is that nothing is foreseen in UML to define such generic types. You may therefore extend UML with an and-hoc profile to use a «concept» stereotype. You would then define concepts exactly like classes, define the constraints using the UML constraints, and use the concepts in UML class templates.

Here, how the second approach would look like. Note the realization dependency between two concepts:

enter image description here

like image 133
Christophe Avatar answered Nov 04 '22 08:11

Christophe