如何从给定的Java类创建UML图?

时间:2015-10-21 19:02:58

标签: java constructor uml

我想知道如何从我已编写的java类创建UML图。我有一个主要问题是我需要在UML图的这个框中包含所有覆盖函数吗?其他一切看起来也正确吗?在UML讲座期间,我病得很重,所以我不得不自学,对自己的工作没有100%的自信。

这是我的java类,然后我将发布我为这个类制作的图表。

public class Dog extends Pet implements LicensedPet, TrainedDog {

public static final String GENUS = "canis";

private Boolean isHappy = false;
private Boolean isSitting = false;
private LocalDateTime whenLicensed;

public Dog(String name, int age, Gender gender) {
    super(name, age, "dog", gender);
}

public void petDog() {
    isHappy = true;
}

public void praiseDog() {
    isHappy = true;
}

public void yellAtDog() {
    isHappy = false;
}

public Boolean getIsHappy() {
    return isHappy;
}

public String getIsHappyAsString() {
    if (isHappy) {
        return "happy";
    } else {
        return "sad";
    }
}

@Override
public String[] getCoreVaccines() {

    String[] coreVaccines = {
        "Rabies 1-year",
        "Rabies 3-year",
        "Distemper",
        "Parvovirus",
        "Adenovirus"
    };

    return coreVaccines;
}

@Override
public String[] getNonCoreVaccines() {

    String[] nonCoreVaccines = {
        "Parainfluenza",
        "Bordetella bronchiseptica",
        "Lyme disease",
        "Leptospirosis",
        "Canine influenza"
    };

    return nonCoreVaccines;
}

@Override
public Boolean isLicensed() {
    return whenLicensed != null;
}

@Override
public void assignLicense() {
    whenLicensed = LocalDateTime.now();
}

@Override
public LocalDateTime whenLicensed() {
    return whenLicensed;
}

@Override
public void sit() {
    isSitting = true;
}

@Override
public void unsit() {
    isSitting = false;
}

@Override
public String speak() {
    return "Yawyahwer";
}

@Override
public String bark(int numBarks) {
   String barks = "";
   for (int i = 0; i < numBarks; i++) {
       barks += "bark!";
   }

   return barks;
}

@Override
public String toString() {
    String info = super.toString();

   String updatedInfo =  String.format("%s, isHappy: %s", info, isHappy);

   if (whenLicensed != null) {
       updatedInfo +=  ", whenLicensed: " + whenLicensed;
   }

   return updatedInfo;
}
}

这是我到目前为止为这堂课创作的内容。

    Dog
---------
    +GENUS:string 
    -isHappy:boolean
    -isSitting:boolean
    -whenLicensed:LocalDateTime
----------------
    +«constructor»Dog(name:string, age:int, gender:gender)
    +petDog()
    +praiseDog()
    +yellAtDog()
    +getIsHappy():boolean
    +getIsHappyAsString():string

感谢您的帮助,我很感激

2 个答案:

答案 0 :(得分:1)

您可以将ObjectAid插件添加到eclipse并在那里轻松检查类(拖放到类图画布上)。 http://www.objectaid.com/

这就是你的狗类的样子 UML for DOG

答案 1 :(得分:0)

如果要覆盖继承的类方法,则应将它们添加到类的方法隔离专区。但是,您不需要添加纯继承的类。我对ascii表示不是那么坚定,但是你需要告诉Pet的泛化以及两个实现的接口。