Sparx Systems Forum
Enterprise Architect => Uml Process => Topic started by: spencer_jones on September 16, 2004, 01:39:43 am
-
In my software I need to model a number of separate threads. These are worker threads so they are global functions rather than part of a class.
What is the usual UML process for modelling a global function so that the design shows which class is creating the thread and allows the global function to further be modelled?
-
Threads are normally modelled as active classes (IsActive = true), regardless of how they are implemented.
If you want to do code generation and make it work with your implementation of threads it presents some other issues, of course.
But you also make me a bit curious as to why you want global functions. In my experience, it gives a lot of advantages to implement each thread as a class. What platform is your code going to run on?
Mikkel
-
Platform is Visual C++ 2003 using MFC. I am creating a worker thread using AfxBeginThread() which I am using to point to a global function rather than a function within a class.
I pass a specialised object as a parameter to the thread function to deal with all the synchronisation of data between the threads.
As the work to be done by the thread is fairly simple I find it is "cleaner" to use a single function rather than to create a more complex class.
I'm not too worried about code generation. The intention is just to model that my application class is creating a thread and the interaction between them.
Thanks for your help,
Spencer.
-
Ok, I would model that it one of these ways:
1. Create an active class to represent the thread and add your function to that class. Give the class a stereotype of your own choosing, such as <<global_thread>>.
2. Create a class to represent the global namespace (call it something like "Globals") and assign all your global functions (and perhaps variables) to that.
Still, in your situation I would prefer to implement the threads as classes, because in my world "global" and "clean" are mostly contradictory terms. By making the functions global you are granting access to them to everything. Therefore you have no easy way of determining what impact a change in one of those functions might have on the rest of the system (anyone might be calling them). Encapsulation in a class helps in that respect. If the threads have things in common, you might also benefit from creating a parent class, CWorkerThread, and deriving each of the thread classes from that.
Mikkel