Android – How to represent the call to a class through another class using an UML Class Diagram

androidclass-diagramuml

In Android, let's say we have 2 classes which have common methods for starting a service, so we extract them to a helper class:

classes of the diagram

The following diagram shows my strange attempt to represent it. I have used transaction narrows. I think those are for the activity diagrams, but in the uml-diagrams.org/class-reference.html, those narrows are called Association Navigability. That's why I have used them to try to represent the diagram. Between HelperClass and ClassService I have used a normal association. Between the classes and the service I have used a restriction (it is just informative, to make it more clear):

my representation attempt

Am I mixing the class diagram with the activity diagram?

UPDATE 1: attempt to represent it with a component diagram:

component diagram

Note: my favourite explanation of how to use a component diagram is this: https://www.ibm.com/developerworks/rational/library/dec04/bell/

UPDATE 2: attempt to draw the class diagram with the suggested changes:

class diagram update

UPDATE 3: full class diagram. Transaction arrows have been changed by associations. User and System interactions have been removed (e.g. startsWhenClick by starts; startsWhenDetection by starts):

full class diagram

Best Answer

Yes, you are mixing processes and structures. Class diagram is a structure diagram, no processes are shown here, mere dependencies. You can use dependency <i> for instantiating, but this only means that one class needs the other and what for. Yes, it is a bit about processes, but MAINLY class diagram is about structures.

Cooperation of Android components (Activities, Services, etc.) should be shown by Component diagram, not class diagram. There you can draw, what messages are sent, who call whom and so on. Class diagram are for more thorough analysis. You can use some classes in component diagram, too. But don't forget to show, to which component the class belongs, as you have forgotten to do here. Use nesting/containment relationship for this.

And on arrows from Activities you use the word "click". Aren't you trying to describe the UI here? That is for one more diagram. There is NO standard diagram for UI planning, but I could advice the use of class diagram elements for it. But it is NOT a class diagram, it is UI diagram, that uses class diagram elements.


As for class diagram:

You can draw dependencies from activities to Service. Such info, as who starts, who stops and so on, could be also on notes in class diagram, or, if it is not absolutely necessary, move it to Activity diagram.

On the association HelperClass - ClassService the multiplication on the target side should be 0..1. Service is not ALWAYS there, is it?

Launcher is a bad stereotype. Better give the name Launcher to the class and if you think it doesn't explain the situation, anchor a note to it.

Relationships of activities classes are not defined.


So, it seems, you have tried to put 4 diagrams in one. It would never work. Divide them or at least, clean the one that you've chosen. And if you are choosing, what ONE diagram to do, choose Component one - it is the most common and will be the most useful.

Edit: How to show that a class is included in a component - 2 ways. You can include class into component and you can connect them by nesting relationship. Both ways are equivalent in the content sense.

enter image description here

Related Topic