簡體   English   中英

將 UML 圖轉換為代碼

[英]Converting a UML Diagram into Code

我在將此 UML 圖設置轉換為代碼時遇到問題。 我知道 Class 是最上面的部分,后面是變量和方法。 我對 Java 很陌生,這可能是我遇到過的最令人困惑的事情。 我不是 100% 確定如何為此創建“模型”或主要代碼部分,但這是我到目前為止為域 class 開始/嘗試的代碼。 我在正確的軌道上嗎? 還是我完全迷路了。 任何提示或向我發送正確方向的信息將不勝感激。

在此處輸入圖像描述

  //This is the main .java file
  public class Assignment3 extends Application {



@Override
public void start(Stage stage) throws Exception {
    Group root = new Group();
    Scene scene = new Scene(root);
    Canvas canvas = new Canvas(400, 300); // Set canvas Size in Pixels
    stage.setTitle("FXGraphicsTemplate"); // Set window title
    root.getChildren().add(canvas);
    stage.setScene(scene);
    GraphicsContext gc = canvas.getGraphicsContext2D();

    Castle stateDomain = new Castle();
    Castle drawDomain = new Castle();

    stage.show();
    }
 

 public static void main (String[] args) {
     launch ( args );
 }

 // .class file that is utterly awful and I don't know where to go
 
 public class Castle {


 private String castleName;
 private double castleSize;
 private double castleX;
 private double castleY;
 private int domainX;
 private int domainY;
 private String castleColor;
 private String domainName;



public void stateDomain ( String castleName, int domainX, int domainY, String castleColor ) {
    this.castleName = castleName;
    this.domainX = domainX;
    this.domainY = domainY;
    this.castleColor = castleColor;    
}

public void drawDomain ( GraphicsContext gc ) {
    
    
    
}

我想指出我只是在尋找一些方向。 此時的任何事情都會非常有用,無論是指向另一篇文章的鏈接還是讓我的大腦運轉的一小段代碼。 謝謝你。

static 描述類之間關系的最抽象方法是使用關聯鏈接,它簡單地說明兩個或多個類之間存在某種鏈接或依賴關系。 有弱協會和強協會。 對於你的情況,我會認為它是強關聯。

public class Domain 
{
    private double x, y, size;
    private String name;

    public void state(String name, int x, int y, Color color) {
            //TODO
    }

    public void draw(arguments) {
        //TODO
    }
}


public class Castle
    {
        //all arguments in diagram and now you need a reference to the class Domain

        private Domain domain;

        //The rest is just writing what is in the diagram

    }

但我必須說你的圖表非常不完整。 請看: https://en.wikipedia.org/wiki/Class_diagram

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM