1

Does UML Class Diagram support expressing Concept?
Also, is there any other diagrams that expresses Concept?
Just in case of misunderstanding, I mean the "Concept" in C++ and generic programming.

Rapptz
  • 20,807
  • 5
  • 72
  • 86
  • I'm not 100% sure you can achive it fully in UML, but you should probably start from **parametrised class** ("template" class) in UML and see if it can be of help somehow. In addition you will certainly need **stereotypes** and possibly **tagged values** to refine your definition. Concepts sintactically look like stereotyped template classes. – Aleks Jun 24 '14 at 07:13
  • It seems worth a trial. Thanks. –  Jun 24 '14 at 18:12
  • Your question is interesting (+1 for newness), but try to do at least the first search for an answer yourself the next time. – Gangnus Jun 26 '14 at 08:04
  • @Aleks Concepts propose universal rules, appliable to any elements that are subjects to some pattern. There are NO tools in UML for expressioning this. By tools proposed by you it is possible only to say about existence of a concepts, but not to tie it to the subject elements. – Gangnus Jun 26 '14 at 08:08
  • @Gangnus, unfortunatelly I don't know enough about the concepts, so I'm not in position to discuss it. :( I just know that UML is very flexible and its semantics can be adjusted quite a lot. For example, C is not OO and you can use a stereotyped class to model C-file for example, its methods, variables, depepdencies... I made similar maneuvers many times, modelling even non-IT concepts. – Aleks Jun 26 '14 at 10:54
  • @Aleks Yes, I, for example, set rules for User manual creation in UML. And it works excellently. But UML does not support modelling of universal or even mere syntactical *rules*. Of course, you can go in detail and simulate them in some behavioral diagram, but surely it is not what you or anybody else need. – Gangnus Jun 26 '14 at 10:59
  • @Gangnus, Thanks. Actually, I have searched for months, believe it or not. –  Jun 26 '14 at 12:53
  • @Gangnus, Would you mind to elaborate what you mean by "universal or even mere syntactical rules"? –  Jun 26 '14 at 12:53
  • @NickyC "... concept says that any type that has an operator < that takes two objects of that type and returns a bool will be considered ..." (wiki). As for your long searching, it is good then to give in the question the best info you have reached so far, for us not to repeat your work and to use the vocabulary you are already accustomed to. I understand, that sometimes that rule is unusable, but mostly it is a good rule. – Gangnus Jun 26 '14 at 13:27

3 Answers3

1

Basically the question can be answered with an answer to the "base class" question : "does UML make any attempt to make it 1-to-1 fitting to C++?"

Answer is simply "no".

This is a very common misunderstanding, one can meet people looking for possibilities of expressing a pointer in UML or any other C++ specific things. You will unluckily not find it.

The misunderstanding is comes historically from the availability of C++ code generation engines which come with some UML modeling tools. All those code generation engines come with their own coding patterns to address the transition from model to code. Simply because there is no standard for the transition patterns itself.

UML comes from OMG and OMG has a generation patterns document for (Corba)IDL-to-C++ but none for UML-to-C++.

Furkan Eke
  • 11
  • 3
0

After reading shortly Wikipedia explanation of C++ "concepts" it looks to me like tool with same goals as generic classes and type constraints in C#

If I understood it correctly then by following older Stack Overflow question Representing a C# Generic Method in a UML Class Diagram it turns out that you should check the http://www.uml-diagrams.org/template.html as already suggested by @Aleks

Basically I mean to model your interfaces and classes as you'd normally do it. Just use the templating annotation and you can also chart some type restrictions using a virtual dependency, inheritance associations between the formal parameters used in the template

Community
  • 1
  • 1
xmojmr
  • 8,073
  • 5
  • 31
  • 54
  • It seems to be the closest thing so far. And I like your reference to existing practice. –  Jun 25 '14 at 10:04
-1

You can show in UML all structures used by concept - i.e., functions, algorithms, classes and so on. But not the concept itself, for it is an element creating syntax.

Also, you can't show in UML macros, preprocessor commands, etc.

All these things simply do not belong to model, but to the language/grammar/syntax. There are other tools for their support. Formal grammars, theories, etc. Yes, there are diagrams for it. Look for "formal grammar diagrams" in google and you'll see heaps of them.

Gangnus
  • 24,044
  • 16
  • 90
  • 149
  • Concept is just a syntactic element? Why? Isn't we modeling things with Concept for years? Concept is not even a syntactic element of C++ yet, although we do have experimental implementation for it recently. –  Jun 24 '14 at 17:44
  • @NickyC No. it is NOT just a syntactic element. It CREATES syntax. Use of concept is creating the grammar, specific to your application. – Gangnus Jun 25 '14 at 10:07
  • Concept creates grammar? How? And still, Concept models things, right? I don't think we can compare preprocessor directives to Concept. –  Jun 25 '14 at 12:08
  • @NickyC "... concept says that any type that has an operator < that takes two objects of that type and returns a bool will be considered ..." (wiki) Sorry, it IS creation of grammar, like it or lump it. – Gangnus Jun 26 '14 at 08:00
  • It is still weird to say so. Concept is not a new thing. Concept naturally emerges when we use template. Concept is already there, even without compiler support or syntactic support. And thus the grammar is already there in the Standard Library for decades, even without "Concept as a (proposed) C++ syntax". –  Jun 26 '14 at 13:15
  • Regarding your example, if a function template compares two operands using a less-than operator, the operands are required to be really less-than comparable, not just supporting less-than operator. Otherwise, the behaviour is not a less-than comparison by definition. However, a compiler that supports "Concept as a syntax" cannot distinguish "really less-than comparable" from "supporting less-than operator". That is where "Concept as modeling" is important. –  Jun 26 '14 at 13:24
  • @NickyC The fact that something is up to existing grammar, does not mean it can't influence its further development. (as in this case). As for your last message, I am afraid I didn't catch it wholely. But notice, I am not saying that this side of concept is not useful. It is VERY useful and powerful. But not supported by UML. UML is not an ideal tool. For example, try to show on one class diagram two different unnamed classes based on one ancestor. It is very hard in UML and impossible in existing tools. – Gangnus Jun 26 '14 at 13:32