Which is equivalent to (python-) module in UML

in UML, there seems to be no element that is the equivalent of a module in python, or at least I haven't figured it out yet.

a module in python represented by a single .py file has a header where imports are indicated. it can contain many classes, all classes are in the module namespace and can directly communicate with each other and have access to the packages / modules / classes that the module imported. how can i draw this on a chart?

update 1: finally, I came across a webpage where I found something that seems relevant ... on this site ( http://www.alan-g.me.uk/l2p/tutclass.htm ) in chapter "Mixing classes and modules" the author says:

"... We can represent this graphically in UML in two ways. The logical grouping of classes can be represented using the Package or we can represent the physical file as a component ..."

if correct, the module in python is similar to the component in UML. I'm still trying to understand how this can work (because the component in UML does not seem to me the same as the module in python), and how and in which diagram I can model it.

update 2: I am testing it with a visual paradigm (without creating code). at the moment, I was able to see that in the UML model, the component-element has a behavior similar to a folder, for example, a package. and when I hover over the classes that are contained in the component, I can see the effect I need, a component representing its own namespace.

now (if this is the correct way to model it), where can I indicate which other packages / modules / classes this module should import? when I select a package in the visual paradigm, it offers me the opportunity to import packages. but when I select a component, import functionality is not offered. Thanks a lot in advance.

+5
source share
1 answer

Note that the concept of a module is just a method of ensuring code reuse and organization in Python. The relationship between Python modules and UML packages and components is not direct and depends on the role of a particular module.

Sorry, I am not programming in Python, so I may have a misunderstanding of the typical use of the module (or I might skip something). However, since I understand the documentation, you can use Python modules for two main, but slightly different purposes. It can be a component (which is part of the system) or a library (i.e. a reusable set of classes).

The first has a direct view in UML, which is a component. Note that a component is a namespace for its elements (including imported ones). However, the component cannot be imported yet as a namespace that can import packages (see below).

On the other hand (for libraries) in UML, you have a package that you can easily use to model modules that should be imported. A package is also a namespace, but it can be imported using any other Namespece (for example, other packages and components). When a package is imported into some Namespece, its own elements become available when importing a namespace (with some restrictions, see 7.4.3.3 and 12.2.3.2 of the UML specification for more information).

Import is usually displayed in the package diagram.

So yes, your thinking is good.

+1
source

Source: https://habr.com/ru/post/1208791/


All Articles