How to show common .h or .pph header file in UML class diagram?

Viewed 318

Suppose that we have some common header files (e.g. common.h or typedefs.h) which contain the project's common typedefs, definitions, etc.

Also, I want to use these header files throughout my all class diagrams (hence, .c or .ccp files are going to include the common.h or typedefs.h files).

I am using Enterprise Architect.How can I show the dependency of the classes to these files in the class diagrams? Is it necessary to show this relationship in the class diagram at all?

2 Answers

Simply use Artifact elements for your files and draw a dependency.

However, I wonder why you would have them in a class diagram. This is a deployment topic. The classes in UML are language agnostic and any .h is just irrelevant for a class design.

Conclusion: there is no need to show a relationship towards the .h artifact in your class diagram.

Usually, class diagrams do not contain names of source files. But there is a way to show how your application is structured and where the common parts are located.

If you have a complex application, modeled by a lot of class diagrams, then you will probably have organized these class diagrams in multiple folders in Enterprise Architect. For example, you might have a folder called 'Types', containing a class diagram 'common', in which you have modeled everything contained in 'common.h' and a class diagram 'typedefs', in which you have modeled everything contained in 'typedefs.h'. Other folders might represent subsystems, e.g. folder 'ShoppingCart' containing all class diagrams, sequence diagrams etc. pertaining to shopping carts.

At the top level, you could create a package diagram. In a package diagram, each folder in Enterprise Architect is represented by a UML package. The dependencies can be shown using dependency relationships (dashed arrows).

For example, your package diagram could show all your packages ("Types", "ShoppingCart" etc.). Package "ShoppingCart" and all other packages have a dashed arrow pointing to package "Types". This means that all packages depend on the contents of "Types". You could adorn the arrows by the keyword ≪import≫, to indicate that you want to be able to use any element in "Types" in the diagrams in the other packages.

Here is an example from the UML specification:

enter image description here

Related