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?
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:
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.
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.
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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With