4

When writing a UML class diagram for C++ code, is it necessary to include constructors and destructors of the relevant class?

2 Answers 2

1

In many cases, adding constructors/destructors to a C++ class diagram would just be textual boilerplate noise and not really meaningful. Only if you want your diagram to be a complete documentation of your C++ classes, you may want to add constructors.

Contrary to what @Marco is saying below, this is not a matter of the underlying business logic, but a purely ergonomic issue of avoiding cluttering and noise in (typically complex) diagrams.

Sign up to request clarification or add additional context in comments.

1 Comment

This answer is incorrect: stackoverflow.com/questions/4006868/…
0

The constructor can be added if it's part of the business logic, you just don't add a return type.
Would be under the functions/methods section:
+ClassName()
I would not add destructors. Again, depends on whether your business logic needs it.

3 Comments

Depending on the target language (e.g. Python) you could add __init__(self, parms) or in some meta language init(parms) -> ClassName or whatever is convenient.
A constructor cannot be part of the business logic since constructors are a completely technical, and not a business, concept.
No, constructors can enforce business constrains if an entity requires certain characters to exist. For example, an employee cannot exist without an employee ID and name, this is business logic. But a business could not be issuing employee ID's, since it's small and will never keep track of this, then you would not add it, as it's not part of what makes an employee. Everything is use case, that's the joy of UML, it gets adapted to the need of the use case, and as long as everyone understands why, it's correct.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.