UML activity diagram for C code with multiple functions in a unit

64 views
Skip to first unread message

srikar sana

unread,
Jul 7, 2019, 8:40:06 PM7/7/19
to UML Forum
Hi all ,
i am struggling to find information on how to use activity diagrams to model c code.
say there is code as shown below

void func1(void)
{
    func2();
    func3();
    func4();
}

void func2()
{
    Some lines of code ;
    var =func5( & param1);
}

etc.,. how should i model this ?

1. Can i model everything in a single activity diagram ?
2. How to model returning of func2() back to func1() and func5() back to func2() ?
   Should i be modelling it ?

I did my search but was not able to find suitable answer. If this is a repeated question i request for a link to the old question where this question is asked ?
thank for the help .

Alex Jongman

unread,
Jul 8, 2019, 7:37:15 PM7/8/19
to UML Forum
UML diagrams are coding language-agnostic, so it doesn't matter if you want to model C, Java, or Python with it.  

Taking a look at the code you provided and the questions you asked, you it seems to me that you are new to UML and struggling with the granularity of the model.
It therefore is a good exercise to start by first modeling with lowest granularity level.
Find the functions that don't use other functions within them and model them as activity diagrams (one diagram per function), where each activity in the diagram is a statement within your code.
Then find functions that use the functions that you already have modeled an do the same, but now the call of an function (for instance your line: var = func5( &param1); ) is also a single statement an therefore a single activity in your diagram.
Finally when you have modeled the main function of you code you have reached the highest granularity level.

Hope this will help you.

srikar sana

unread,
Jul 9, 2019, 9:04:21 PM7/9/19
to UML Forum
Hi Alex,
Thanks for the reply.
We model the function call also an activity but then where do we model the function ? In a separate activity diagram or in the same one?
Reply all
Reply to author
Forward
0 new messages