UML class diagram: how to model relations about calling a method or starting an activity or service

chelder picture chelder · Feb 10, 2014 · Viewed 10.5k times · Source

I'm creating my first Android app. I have avoided to label associations with user or system interactions (e.g. I have labeled starts instead startsWhenClick; I have labeled starts instead startsWhenDetection). However, after reading this, I'm considering to change the starts associations by << create >> dependencies. I'm confused!

The app works as follow. When the app starts, LauncherActivity will call the methods of BaseActivity to start the activity marked in SettingsActivity (it could be SettingsActivity too). LauncherActivity will launch both services too. This is the diagram:

full class diagram

Note: this question is the continuation of this question.

Answer

Gangnus picture Gangnus · Feb 11, 2014

It is not a real class diagram.

  • Starts and calls belong to notes, or if you are sure you want to see them on connections, do stereotypes on DEPENDENCIES, not associations.
  • You still have no associations, and they are the main part of the class diagram. Look here about how to work with them. You should create associations first. Only after that show the dependencies. (It is not a common rule, but you should do so for better understanding)
  • As for the actions you are trying to show here, do State Machine diagram for them, then probably Sequence or Activity diagram. Don't use Interaction overview diagram, you'll get lost in it.

But stop putting so many actions on the class diagram

IMHO, because Activities have no or almost no structure dependencies, the appropriate class diagram will be very poor - simple blocks without associations. And dependencies all over the field... So, the class diagram is not useful on this level. It seems, I have told you already, that class diagrams are for classes that are in one same Android intent - one or more for an intent.

As for communication diagram, I think it is not your case. It is more common, close to user, than sequence or activity diagrams. It is for the case when you have very many sorts of messages and you are planning their routes. For Camel planning, for example. But alas - it has not implemented message patterns. So, it remains only for very common planning of systems with mass messaging. Your "messages" are starting, initiating components and so on. You can't show it with that diagram.

You can try Object Diagram, or Composite Structure diagram. If you want to show functionality on the class diagram, you can't do it, but you can move to these ones.