如何通过使用UML类图其它类再present调用的类UML、present

2023-09-07 22:44:57 作者:风雪添作酒

在Android上,让我们说我们有2类,它们具有启动服务常用的方法,所以我们提取他们到一个辅助类:

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:

下图显示了我的异样尝试重新present它。我已经使用事务缩小。我认为这些都是为活动图,但在 uml-diagrams.org/class-reference html的,这些变窄被称为的协会适航的。这就是为什么我用他们尝试重新present图。之间的助手类和ClassService我使用了一个正常的关联。类和我使用了一个限制的服务之间(这只是信息,以使其更清晰):

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):

我是混合类图与活动图?

Am I mixing the class diagram with the activity diagram?

更新1 :尝试重新present其与组件图:

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

注:如何使用组件图我最喜欢的解释是这样的: https://www.ibm.com/developerworks/rational/library/dec04/bell/

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

更新2 :尝试绘制类图的修改建议:

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

更新3 :满级图。交易箭已经由协会变更。用户与系统的交互已被删除(如startsWhenClick由开始; startsWhenDetection由首发):

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):

推荐答案

是的,你是混合过程和结构。类图是一个结构图,没有过程被示出,仅仅依赖关系。你可以使用依赖<我>的实例,但这只意味着一个类需要其他什么的。是的,这是一些有关进程,但主要是类图是关于结构。

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.

Android组件(活动,服务等)的合作应该由组件图,而不是类图显示。在那里,你可以借鉴,哪些邮件被发送,谁打电话谁等。类图是更透彻的分析。你可以使用一些类组件图,太。但不要忘了展示,到组件的类属,因为你已经忘记了在这里做。使用嵌套/包含关系这一点。

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.

和从活动,你用的是箭点击。你是不是想在这里描述的用户界面?这对于多一个图。没有为用户界面的规划没有标准图,但我会劝告使用类图元素吧。但它不是一类图,它的UI图,使用类图的元素。

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.

对于类图:

您可以从活动服务得出的依赖。这样的信息,如谁启动,谁停止等,可以同时在类图笔记,或者,如果不是绝对必要的,它移动到活动图。

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.

在关联助手类 - ClassService在目标侧的乘法应0..1。服务是不是总是存在的,是吧?

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.

所以,现在看来,你试图把4图于一体。它永远不会成功。他们分开,或者至少,清,你所选择的人。如果你是选择,什么人图做的,选择组件之一 - 它是最常见的,将是最有用的。

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.

编辑:如何显示一类包括在一个组件 - 2种方式。您可以包括全班分成组件,您可以通过嵌套关系将它们连接起来。这两种方法都在内容意义上等同。

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.