UML類圖靜態方法依賴 (UML class diagram static method dependecy)


問題描述

UML類圖靜態方法依賴 (UML class diagram static method dependecy)

我有 3 個類:A 類和 B 類。它們有變量。C 類沒有變量,只有 A 類和 B 類使用的靜態方法。

我的第一個問題是如何使用 UML 類圖來表示它?我正在考慮使用從 A 到 C 和從 B 到 C 的虛線箭頭 ( ‑‑‑‑‑> ),箭頭上帶有“usesStatically”消息。這是正確的嗎?

另外,我的第二個問題是我是否代表了我的 A 和 B 類的 main() 方法?這是他們唯一擁有的,而且他們使用 C 內部的方法;C 沒有 main(),只包含靜態方法。

代碼如下:

    Class A  {
      main()
      {
      C.method1();  
      }
   }

class B:

Class B{
    main()
    {
    C.method2();    
    }
}

class C:

   Class C{
method1(); 
method2();
}

第三,我的最後一個問題:在我的UML類圖中,method1() 屬於 A 類或 C 類,還是兩者都屬於?同樣,method2() 屬於 B、C 還是兩者都屬於?


參考解法

方法 1:

Class Diagram is a structure diagram, and thus you are not interested in the way particular methods call each other, rather you focus on capturing classes and their relations. So instead of saying "instance of A calls C.method1", you simply say that A uses C.

enter image description here

Adding main() is questionable. If such method makes sense in your domain then include it, if the only reason is that that's the entry point in your language, you should probably omit it as it doesn't add value to the diagram.

If you want to capture the actual method calls between the classes, UML has behavior diagrams for that, here namely

Communication Diagram, and

enter image description here

Sequence Diagram

enter image description here

(by vici30Peter Uhnak)

參考文件

  1. UML class diagram static method dependecy (CC BY‑SA 2.5/3.0/4.0)

#java #uml #static






相關問題

電子郵件地址中帶有 + 字符的 Java 郵件 (Java mail with + character in email address)

如何快速原型化 Java 代碼? (How to quickly prototype Java code?)

如何使用 Maven 在目標(SVN-)服務器上創建 Javadoc? (How to create Javadoc on the target (SVN-) server using Maven?)

為什麼檢查二叉樹有效性的解決方案不起作用? (Why the solution for checking the validity of binary tree is not working?)

Selenium webdriver通過第一個數字找到texy (Selenium webdriver find texy by first digits)

setOnClickListener 沒有在圖像視圖上被調用 (setOnClickListener is not getting called on image view)

繪製多邊形:找不到錯誤 (Drawing Polygon : unable to find error)

半透明 JButton:對像出現在背景中 (Semi-Transparent JButton: Objects appear in Background)

比較同一數組的元素 (Compare elements of the same array)

Java 屏幕截圖小程序 (Java screen capture applet)

Minecraft 1.8.9 Forge Modding 的Java 開發工具包,需要什麼JDK/JRE,代碼是否正確? (Java Development Kit with Minecraft 1.8.9 Forge Modding, What JDK/JRE Is Needed, Is Code Correct?)

java while (resultset.next()) 不返回同一列中的所有數據 (java while (resultset.next()) does not return all data in the same column)







留言討論