2

I have a number of free functions in a couple of Python modules and I need to create a UML Class Diagram to represent my entire program.

Can I represent a free functions in a Class Diagram somehow or do I need to create a Utility Class so I can represent them in my Class Diagram?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Dalecn
  • 77
  • 7
  • I think you need to add a utility class to do that. because in class diagram functions are usually an operation used in a class component. – Eitan Rosati Apr 29 '21 at 14:51
  • If you have a specific code in python. you can generate a UML with some libraries or if you code in pycharm you can use this https://www.jetbrains.com/help/pycharm/viewing-diagram.html#a22d32d8 – Eitan Rosati Apr 29 '21 at 15:01
  • Does this answer your question? [Is it possible to visualize a bunch of functions in UML](https://stackoverflow.com/questions/63914558/is-it-possible-to-visualize-a-bunch-of-functions-in-uml) – Christophe Apr 29 '21 at 21:29

2 Answers2

0

You will need to have some class in order to represent a "free function". You are quite free in how to do that. What I usually do is to create a stereotyped class. And it would be ok to use «utility» for that. Anything else would work, but of course you need to document that in your domain.

Usually a stereotype is bound to a profile. But most tools allow to use freely defined stereotypes. Though that is not 100% UML compliant it is quite a common practice.

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
0

Even though UML was conceived in a time, when object orientation was hyped, it doesn't mean that it cannot be used for functions. What many don't realize is, that Behavior in the UML is a Class. Therefore, any Behavior can be shown in a class diagram. Just put the metaclass in guillemets above the name, e.g. «activity». If you plan to describe the function with an activity diagram, that makes perfect sense. However, if you plan to describe it in (pseudo) code or in natural language, you can use «function behavior» which is defined as a behavior without side effects. Or, if it can have side effects, just use «opaque behavior».

Axel Scheithauer
  • 2,758
  • 5
  • 13