4

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

chelder
  • 3,819
  • 6
  • 56
  • 90
  • Excellent. Only I would show HelperClass as a class and would show what component it belongs to. – Gangnus Feb 06 '14 at 14:18
  • And beware, IBM rational is much up to UML standard. They have they own standards and you could get problems with understanding. – Gangnus Feb 06 '14 at 14:20
  • @Gangnus, I promise I actually don't know how to represent what you say (the HelperClass as a class showing the component it belongs to). On the other hand, at **UPDATE 2**, I also added a new class diagram trying to follow your recommendations. It is weird for me to use a class diagram when it won't be database related though, specially to specify the multiplications. Is it OK? – chelder Feb 06 '14 at 14:57
  • Look the edition. No, that last one is a step to the dreadful past :-) – Gangnus Feb 06 '14 at 15:28
  • Simply change on the Comp.Diag. helper class to a class block and add nesting connection to component, that contains it. Or ... Ah! It is the class that is a component by itself, is it? It somply doesn't belong to any other Activity or Service, yes? Then, your second diag is correct. – Gangnus Feb 06 '14 at 15:32
  • @Gangnus, it is: each class corresponds to a component in this example. Do you think that the two updated diagrams are correct then? – chelder Feb 06 '14 at 19:55
  • Only third one is correct, for class DIAGRAM can't have behaviour arrows on it. They belongs to COMPONENT diagram, in which the same CLASSES normally have behaviour arrows, either being shown as classes or as components. As for class diagram, you show there what classes have instances of other classes as attributes or references or results/params of methods. – Gangnus Feb 06 '14 at 22:28
  • And you can insert in component everything, you needn't put its functions into the note. – Gangnus Feb 06 '14 at 22:29
  • OK. So for you, is the **component diagram** the best diagram you know to represent the classes and its methods? The **class diagram** seems **only for** the model or database related part. By the way, I just discovered that I probably should ask this question here: http://programmers.stackexchange.com/tour Thanks for all your help @Gangnus! :) – chelder Feb 07 '14 at 13:17
  • Excuse me, but it seems, that I had misguided you. Component diagram is for components - large chunks of many classes each. Sometimes a class or two can happen there. You show there the structure at large and the signals/messages/calls between these chunks. Oh, what classes should appear there are classes of messages. ... And class diagram is mostly a diagram for one component and classes in it, how one sees the others. Visibilities, navigability, generalization. OOP patterns are described in class diagrams. But you have very small components, small as classes. So, these two diag can be mixed. – Gangnus Feb 07 '14 at 13:35
  • Class diagrams are very good. I use them even for modelling UI or structured documents. But YOURS class diagrams here were not OK. Try to put here on SO your next, really class diagram and we'll discuss it. And don't forget to check answers :-) – Gangnus Feb 07 '14 at 13:42
  • And among other things, you can model Databases using class diagrams elements, too. – Gangnus Feb 07 '14 at 13:54
  • I have remaked the full class diagram. I have uploaded it to **UPDATE 3** – chelder Feb 07 '14 at 18:38
  • @Gangnus, the *HelperClass* would be the *BaseActivity*, their methods are used by more than one class. – chelder Feb 07 '14 at 18:44
  • from [here (the answer is yours, @Gangnus btw)](http://programmers.stackexchange.com/questions/211886/how-can-i-indicate-if-an-object-operates-with-another-one-in-an-uml-class-diagra), I'm considering to change the *starts* associations by *<>* dependencies. I'm actually confused! – chelder Feb 07 '14 at 20:31
  • Please, make your class diagram another question. It is the rule - we have finished with the first one, now let's go to the second. In another question.... My answer was to the question, how to show instantiating. Please, notice, that it is an ADDITIONAL ability of class diagram. As for the main ones, look for them in another my answer, please: http://stackoverflow.com/a/21478862/715269 – Gangnus Feb 07 '14 at 21:38
  • I posted the new question here: http://stackoverflow.com/questions/21689109/uml-class-diagram-how-to-model-relations-about-calling-a-method-or-starting-an – chelder Feb 10 '14 at 22:21

2 Answers2

1

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

Gangnus
  • 24,044
  • 16
  • 90
  • 149
  • I'm glad I have invented a new diagram haha. **I updated my question with a new component diagram**. Just for your curiosity: It is curious I have never learnt about the component diagram in the university. It is even more curious that, in contrast with [Wikipedia in English language](https://en.wikipedia.org/wiki/Component_diagram), the [Wikipedia in Spanish language](https://es.wikipedia.org/wiki/Diagrama_de_componentes) asks about use cases instead. – chelder Feb 06 '14 at 14:13
0

Draw class diagram with operation definitions. And sequence diagram where you can define communication between lifelines of two classes. Put thirt lifeline for mediator and draw messages. This way you can described that two instances communicate through mediator.

Vladimir
  • 2,066
  • 15
  • 13