将Java代码转换为UML图

问题描述 投票:2回答:1

我必须将以下Java代码转换为UML图,但是我不确定我是否正确地完成了类之间的关联。请您告诉我UML图是否正确。

public class Booking {

    private String name;

    private Time time;

    private Table[] tables;

    public Booking ( String n, int st, int en, int num ){
    }

    public int getStart (  ){
        return 1;
    }

    public int getEnd (  ){
        return 1;
    }

    public Table[] getTables (  ){
        return new Table[3];
    }

    public int getBookingSize (  ){
        return 1;
    }
}
public class Time {

    private int startHour;

    private int endHour;

    public Time ( int st, int en ){
    }

    public int getStart (  ){
        return 1;
    }

    public int getEnd (  ){
        return 1;
    }
}
public class Table {

    private int number;

    private int seats;

    public Table ( int num, int sz ){
    }

    public int getNumber (  ){
        return 1;
    }

    public int getSeats (  ){
        return 1;
    }
}
public class Restaurant {

    private Booking[] bookings;

    public void makeBooking ( String n, int st, int en, int s ){
    }


    public void cancelBooking ( String n ){
    }

    public Table[] getTables ( String n ){
        return new Table[2];
    }

    public int getStTime (String n) {
        return 1;
    }

    public int getEndTime (String n) {
        return 1;
    }
}

enter image description here

java uml class-diagram model-associations
1个回答
1
投票

我将忽略方法和属性,因为它们是微不足道的并且没有意义(理想情况下应该省略getter)。

enter image description here

您的图表有几个不同之处:

  • Restaurant可能根本没有任何预订,所以它应该是*,而不是1..*
  • Booking只需要一个Time,因为Time已经包含了开始和结束
  • 我不知道为什么Restaurant有开始和结束时间。我将假设它是显示开放时间(这是Time的单个实例。
  • 根据你的代码,你可以在不止一个Booking上有Table。在您的图表中只有一个是可能的。
  • 一个Table可能有许多Bookings。在你的图表中,它只能有一个。 (当然有运行时限制,两个Bookings不应该在同一个Table期间预订相同的Time,但是应该用OCL或作为注释表示)
  • 为关联端点添加了角色名称(periodopeningHours,...)

更多说明:

  • Time应该包含一次,或者它应该重命名为PeriodTimeInterval。目前的命名令人困惑。
  • Time关系另一方面的多重性可以省略(因为它们在这里没有多大意义)。
© www.soinside.com 2019 - 2024. All rights reserved.