1

Should I put deleted method or member function in an UML class diagram, i.e. for example for a class like this:

class ProfilometerManager
{
    int a = 6;
public:
    ProfilometerManager(ProfilometerManager& other) = delete; //can not be cloneable
    ProfilometerManager& operator=(const ProfilometerManager&) = delete; // can not be assignable
};
Christophe
  • 68,716
  • 7
  • 72
  • 138
Gameriker
  • 35
  • 7
  • 1
    Its opinion based, what I usually do is define a base class NonCopyable and use that in my diagrams. Or I add a role <> and put that in. Rationale : NonCopyable is a reusable concept (like <>). Note I would also derive ProfilemeterManager in code from NonCopyable – Pepijn Kramer Dec 19 '21 at 17:24
  • Thank you : ) how can I mark your comment as the answer? – Gameriker Dec 19 '21 at 17:44
  • @PepijnKramer Its not opinion based at all: the notation is not compliant with UML syntax. But I support your idea of defining a stereotype to identify relevant concepts, be it at class or at feature level. – Christophe Dec 19 '21 at 19:36
  • Since the question is about showing deleted members in an UML class diagram, and since the UML 2.5.1 specifications are very explicit about whether this is possible and compatible with the UML syntax, I vote to reopen this question. This is not opinion based and I would invite close-voters to consult chapter 9 of the UML specifications to find out why. – Christophe Dec 19 '21 at 23:36
  • @Christophe Maybe I've phrased it wrong then, I know its not standard UML so that's why I thought my answer would be an opinion. And stereotype was the word I was looking for. – Pepijn Kramer Dec 20 '21 at 04:41

1 Answers1

1

The UML notation does not support this notation. The UML specifications define a syntax with = for default values of attributes but not for operations (member function). A suffix = delete behind an operation in a class-diagram would be syntactically incorrect and confusing for most of the readers, even if C++ practitioners would understand it. Therefore you should not use such a notation (even more if considering it as an implementation detail).

UML has no build-in way to express the absence of an operation in the same way than =delete in C++: if an operation is not shown on an UML diagram, it can mean that it does not exist or that it exists but is simply not relevant for the purpose of the diagram.

In this regard, if the deletion would be vital for your design:

  • if this is rather rare, the simplest way would be to add a note to the class, in plain text.
  • if this is very common and important in your domain, you could consider defining a stereotype in an UML profile, i.e. «Deleted».

If it is not really the deletion of individual member functions which is important for your design, but their effect for the class (e.g. «not copiable» as suggested by Pepijn Kramer's comment), you may better express this with ad-hoc class stereotypes. This would be far more expressive and you could map the design to implementation rules without getting lost in too much details.

Christophe
  • 68,716
  • 7
  • 72
  • 138