Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I include private methods into UML class diagram?

Tags:

uml

So the question is simple. I just do not find the answer on the internet. I think private methods are useless in diagram, not telling much. But maybe I think wrong.

like image 905
Dariux Avatar asked Jul 21 '16 08:07

Dariux


People also ask

Can you show a private feature on a UML diagram?

In general UML provides a mechanism to show operation (and attribute alike) visibility. As private feature can be depicted on a diagram it is clear that you can present it on a diagram. However if you show it or not depends what you're modelling. If you're modelling the internal behaviour of the class then yes.

When to include private methods in a class diagram?

Private methods are an implementation detail of the class, not its public API. If you are using the diagram to show the external interface of the class, or some subsystem that the class is part of, then there is no reason to include them.

What is a class diagram in UML?

Class diagrams are one of the most useful types of diagrams in UML as they clearly map out the structure of a particular system by modeling its classes, attributes, operations, and relationships between objects.

How do you show a composition relationship in a UML diagram?

To show a composition relationship in a UML diagram, use a directional line connecting the two classes, with a filled diamond shape adjacent to the container class and the directional arrow to the contained class.


2 Answers

Private methods are an implementation detail of the class, not its public API.

No:

If you are using the diagram to show the external interface of the class, or some subsystem that the class is part of, then there is no reason to include them. They will just add visual noise and confuse the reader.

Yes/Maybe:

On the other hand, if you are trying to communicate the internal design of the class itself, or its tightly coupled collaboration with another class (think of friend in C++), then it might be appropriate.

like image 152
Peter Uhnak Avatar answered Jan 04 '23 06:01

Peter Uhnak


Opinion:

UML is not* a 4GL programming language. You use it to convey an idea, design, architecture. You only add information that serves that purpose. It does not have the concept of being "complete". Like text in a book, you only use words necessary for the purpose of conveying the message.

If it is used as part of system documentation, and it needs to show all members, then we just generate it afterwards.

UML is not the goal, it is just a modelling language to communicate with people.

So if it serves the purpose you add it, otherwise you leave it out.

*) some attempts have been made at that, but have not been very succesful (togetherJ springs to mind)

like image 44
raphaëλ Avatar answered Jan 04 '23 05:01

raphaëλ