简体   繁体   English

将 UML 图转换为代码

[英]Converting a UML Diagram into Code

I am having issues converting this UML Diagram setup into code.我在将此 UML 图设置转换为代码时遇到问题。 I understand the Class is the top portion followed by the variables and the methods.我知道 Class 是最上面的部分,后面是变量和方法。 I am very new to Java and this is probably the most confusing thing I've ever encountered.我对 Java 很陌生,这可能是我遇到过的最令人困惑的事情。 I'm not 100% sure how to create the "model" or the main code section for this but this is the code I have started/attempted for the Domain class so far.我不是 100% 确定如何为此创建“模型”或主要代码部分,但这是我到目前为止为域 class 开始/尝试的代码。 Am I on the right track?我在正确的轨道上吗? Or am I just completely lost.还是我完全迷路了。 Any tips, or something to send me in the right direction would be greatly appreciated.任何提示或向我发送正确方向的信息将不胜感激。

在此处输入图像描述

  //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 ) {
    
    
    
}

I want to point out I am just looking for some direction.我想指出我只是在寻找一些方向。 Anything at this point would be incredibly helpful, whether it's a link to another post or a sliver of code that gets my brain going.此时的任何事情都会非常有用,无论是指向另一篇文章的链接还是让我的大脑运转的一小段代码。 Thank you.谢谢你。

The most abstract way to describe static relationship between classes is using the Association link, which simply states that there is some kind of a link or a dependency between two classes or more. static 描述类之间关系的最抽象方法是使用关联链接,它简单地说明两个或多个类之间存在某种链接或依赖关系。 There is the weak and the Strong Association.有弱协会和强协会。 For your case i will consider it to be the strong association.对于你的情况,我会认为它是强关联。

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

    }

but i must say your diagram is very incomplete.但我必须说你的图表非常不完整。 Please take a look at: https://en.wikipedia.org/wiki/Class_diagram请看: https://en.wikipedia.org/wiki/Class_diagram

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM