Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the equivalent of a (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 one .py-file, has a header where the imports are denoted. it can contain many classes, all classes are in the modules namespace and can talk to each other directly and have access to the packages/modules/classes that the module has imported. how can i draw this in a diagram?

update 1: finally, i stumbled upon a webpage, where i found something, that seems to be relevant... on this website(http://www.alan-g.me.uk/l2p/tutclass.htm) in the chapter "Mixing Classes and Modules", the author says:

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

if that is correct, a module in python is like a component in UML. i am still trying to figure out, how this can work(because a component in UML seems to me not to be the same as a module in python), and how exactly and in which diagram(s) i can model it.

update 2: i am testing it with visual paradigm community edition(without it's code-generation-feature). for now, i was able to see, that in the UML-model, the component-element has a folder-like behaviour, like a package. and when i hover with the mouse over the classes that are contained in a component, i can see the effect i wanted, of the component representing an own namespace.

now(if this is the right way to model it), where can i specify, which other packages/modules/classes this one module shall import? when i select a package in visual paradigm, it offers me an option to import packages. but when i select a component, no import-functionality is offered. thanks a lot in advance.

like image 993
coffeekid Avatar asked Dec 11 '14 09:12

coffeekid


1 Answers

Note that the module concept is just a method to provide code reusability and organization in Python. The link between Python modules and UML Packages and Components isn't direct and depends on a role of a particular module.

Sorry, I'm not programming in Python so I might have incorrect understanding of a typical module usage (or I can miss something). However as I understand the documentation you can use Python modules for two basic but a bit different purposes. It might represent a component (that is a part of a system) or a library (i.e. reusable set of classes).

The former one has a direct representation in UML that is a Component. Note that a Component is a Namespace for its owned (including imported) elements. However Component cannot be imported yet as a Namespace it 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 importable. Package is also a Namespace but it can be imported by any other Namespece (for instance other Packages and Components). When Package is imported to some Namespece, its owned elements become available within importing Namespace (with some restrictions, see 7.4.3.3 and 12.2.3.2 of UML specification for more details).

The imports are usually shown in a package diagram.

So yes, your direction of thinking is good.

like image 186
Ister Avatar answered Sep 21 '22 06:09

Ister