Creating Compact and Easy to Read UML Class Diagrams
Join the DZone community and get the full member experience.Join For Free
as a solution architect i often get thrown into projects with a lot of legacy code and little or outdated documentation. my mandate is to suggest architectural changes that will reduce maintenance costs and ease further development. the first thing i focus on is to get an overview of the system and how it is structured with modules, components and classes. i have found that the best way to get this overview is to create a light weight uml class diagram. in this post i will show you how i prefer to create light weight uml class diagrams.
to start with i will explain what i mean by light weight uml class diagrams.
i want the diagrams to be easy to read and understand and i try to find the balance where the diagram is so light that non-technical persons (like product owner and project manager) understands it, but still it is technical enough so technical persons (like developers and architects) finds it useful.
i only use a few of the uml class diagram symbols:
in addition to these symbols i frame the packages that logically is related with different colours. i do this to make the diagrams more easy to read and it is also easier to understand the system when packages are framed like this. i use the same philosophy when creating diagrams as i use when writing clean code . i try to align boxes and symbol and make the diagram as easy to read as possible. i also only focus on the most important and essential packages and classes of the system. i do not add anything to the diagram that is not important, that will only be considered as noise.
you should also think twice before creating such diagrams. ask yourself the question if it is really useful to create a diagram for that part of the system before you do so. creating diagrams with the single purpose of creating a diagram is waste of your own time and also waste of time for the persons reading the diagram. most people reads a diagram when they see one. i do so myself because i automatically thinks that since they bother creating a diagram it’s probably covering an important part of the system.
ok, enough talk, let’s look at how i create my light weight uml class diagrams. i use microsoft viso, any program can be used. i simply use viso because i am very familiar with it and that’s the program where i quickest can draw these diagrams (since i have done this quite a few times i actually draw it faster in visio then i would manage to do with pen and paper).
in visio i select the uml model diagram found under software and database. i create a new page for each new module or large and complex components and packages. this way it is easier to focus on a different part of the system. another thing i use to do it to add blank pages containing only some text explaining what i try to show with the diagrams on the following pages. when i am done with my diagrams and want to distribute them i have found that the best way to do so is to save the diagram as a pdf (you can do that directly from visio). then each page in visio will be a page in the pdf file and separated with the blank pages (containing text explaining the system and diagrams or simply containing a header) this pdf file is all you need. no need to place your diagrams in documents with a lot of complimentary text. the keyword is as when developing software kiss (keep it simple, stupid).
to give you some examples i took an old pet project of mine and created diagrams for the most important part of the solution. the project is a windows mobile 6.5 application using gps to track, time and register your workout such as running, cycling etc.
first i will show the diagram for the main module called runsmartwithme. the runsmartwithme module is framed with a blue box showing packages and classes in this module. packages framed with the red box is external modules/libraries that the runsmartwithme module depends on.
next i create a diagram for the techcon.util module that the runsmartwithme module depends on.
and as the last diagram for this example i took the techcon.ui module which runsmartwithme also depends on.
all these diagrams are in separate pages in visio.
some of you might think that these diagrams are not using uml correctly (and i guess that some of you might say that this is not a uml class diagram at all) and that might be true, but i don’t think that really matters. the most important is to be able to create compact and easy to read diagrams without spending too much time doing so.
i also saved the diagrams as a pdf file from visio. you can have a look at the pdf file if you want to see the diagrams there.
by doing this exercise i have gained several benefits:
- knowledge about the modules, components and structure of the system
- i have created good system documentation
- i have a good base to continue my work on suggesting architectural improvements
the next step now would be to create similar diagrams for the new system architecture.
Opinions expressed by DZone contributors are their own.